package com.elite.groovy.callback

import com.elite.groovy.util.EliteBean
import cn.com.elite.PropertiesUtil
import com.elite.groovy.util.Util
import com.elite.groovy.kh.KHDBConfig
import com.elite.groovy.kh.KHUtil
import com.sun.org.apache.xml.internal.security.Init
import net.sf.json.JSONArray
import net.sf.json.JSONObject
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.apache.tools.ant.taskdefs.Get
import org.json.XML
import org.slf4j.LoggerFactory
import org.springframework.jdbc.core.JdbcTemplate

import javax.net.ssl.SSLContext
import javax.net.ssl.X509TrustManager
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;

import com.sun.org.apache.xml.internal.security.utils.Base64;
import java.text.SimpleDateFormat;

/**
 *
 * @Title: autoPushH5YPF*
 * @Description:预评分推送H5系统 *
 * @remak ：预评分推送H5系统*
 * @author: TH*
 * @date 2023-11-27 11:11:00
 *
 */
public class apiPushH5YPF implements ServiceBackInvoke {
    private static final Log log = LogFactory.getLog(apiPushH5YPF.class);

    private static String defaultCharset = "UTF-8";
    static String algorithm = "SHA256WITHRSA";
    static String publicKey = "";    //公钥
    @Override
    String doCallBack(EliteBean eliteBean, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        //获取接口调用方式及参数
        String GetMethod = httpServletRequest.getMethod();
        log.debug("[GetMethod]:" + GetMethod);
        String inData = "";
        if (GetMethod.equals("GET")) {
            inData = httpServletRequest.getParameter("data");
            log.debug("[原始Get请求参数：]" + inData);
        } else {
            InputStreamReader reader = new InputStreamReader(httpServletRequest.getInputStream(), "UTF-8");
            BufferedReader iny = new BufferedReader(reader);
            String line;
            while ((line = iny.readLine()) != null) {
                inData += line;
            }
            log.debug("[原始Post请求参数：]" + inData);

        }

        JSONObject inDatajsonObject = JSONObject.fromObject(inData);
        String Customer_guid=GetJV(inDatajsonObject,"Customer_guid");
        long starttime = System.currentTimeMillis();


        // 获取数据源List<Map<String, Object>>
        JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());

        Init.init();
        String  H5KG=  KHDBConfig.getParam(eliteBean, "H5_KG", "");
        if (H5KG.equals("OPEN")){
            log.debug("预评分自动任务开关状态为开启："+H5KG);


            try {
                //查找待推送H5的名单
                String selectSql =
                        '''                  
                 select distinct 
                 T2.CUSTOMERNAME,
                 h5.customer_guid,
                 T1.frame_code,
                 h5.ISFLAG,
                 T2.CITY_ID,
                 T1.SERVICE_AREA,
                 h5.CUSLISTNAME,
                 h5.CREATEDGROUP
                 from push_H5_customer h5
                 left join Customer T1 on h5.customer_guid=T1.customer_guid
                 Left Join Customer T2 On T2.Customer_Guid=T1.Parent_Guid
                 where 1=1
                 and T2.CITY_ID is not null
                 and T1.frame_code is not null
                 and h5.customer_guid=?
                           ''';
                List<Map<String, Object>> YpfList = jt.queryForList(selectSql,Customer_guid);

                log.debug("本次预评分推送H5数量：" + YpfList.size());

                for (int i = 0; i < YpfList.size(); i++) {
                    Map YpfMap = YpfList.get(i);
                    String CREATEDGROUP = YpfMap.get("CREATEDGROUP");//创建人推送组
                    String customer_guid = YpfMap.get("customer_guid");//客户ID
                    String frame_code = YpfMap.get("frame_code");//车架号
                    String isflag = YpfMap.get("ISFLAG");//车架号 2非续保 1续保
                    String CITY_ID = YpfMap.get("CITY_ID");//城市
                    String SERVICE_AREA = YpfMap.get("SERVICE_AREA");//服务区域
                    String CUSTOMERNAME = YpfMap.get("CUSTOMERNAME");//客户姓名
                    String CUSLISTNAME = YpfMap.get("CUSLISTNAME");//批次ID
                    log.debug("客户ID:" + customer_guid + " 车架号：" + frame_code);
                    //修改批次表状态改成已推送
                    eliteBean.update(" update PUSH_H5_CUSTLIST set  flag='1'  where CUSTLIST_XXX='"+CUSLISTNAME+"'  and CREATEDGRP='"+CREATEDGROUP+"'","dataSource")
                    //执行非续保名单
                    if (isflag.equals("2")||isflag.equals("1")) {
                        //调用执行车型查询方法
                        String h5_v01_status = push_h5_V01(eliteBean, frame_code, customer_guid,CITY_ID);
                        if (h5_v01_status.equals("S")) {
                            //调用保存订单车辆信息方法
                            String h5_v02_status = push_h5_V02(eliteBean, frame_code, customer_guid, SERVICE_AREA, CITY_ID,CREATEDGROUP,isflag);
                            if (h5_v02_status.equals("S")) {
                                //调用报价方法
                                push_h5_V03(eliteBean, frame_code, customer_guid, SERVICE_AREA, CITY_ID,CREATEDGROUP,isflag);
                            }
                        }
                    }


                    /**
                     else if (isflag.equals("1")) {
                     //执行续保名单
                     push_h5_xbPremiumCalculate(eliteBean, frame_code, customer_guid, SERVICE_AREA, CITY_ID, CUSTOMERNAME);
                     }
                     **/

                }





            } catch (Exception e) {
                log.error("【预评分】推送H5异常：" + e.getMessage());


            }

        }else{
            log.debug("预评分自动任务开关状态为关闭："+H5KG);
        }
        long endtime = System.currentTimeMillis();

        log.debug("【预评分】推送处理完毕 耗时(毫秒):" + (endtime - starttime));



        return 1
    }






/**
 * H5车型查询
 * @param eliteBean
 * @param frame_code
 * @return
 */
    public static String push_h5_V01(EliteBean eliteBean, String frame_code, String customer_guid,String city_id) {


        String status = null;
        String xmljson = null;
        String postCallBackBody = null;
        String errMsg=null;
        try {
            Init.init();
            String api = "carType";
            JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());
            Date date = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            String sql = "select WEBSERVICEURL From sysc_interface where WEBTYPE='H5_URL'";
            List<Map<String, Object>> createlist = jt.queryForList(sql);
            String geturl = createlist.get(0).get("WEBSERVICEURL");



            String path = geturl.toString() + "/ecms2/portal";//地址
            String clientName = KHDBConfig.getParam(eliteBean, "H5_SHH", "");//商户号
            String privateKey = KHDBConfig.getParam(eliteBean, "H5_KEY", "");//私钥
            log.debug("【预评分】请求地址：" + path)
            String cityCode=null;
            //消息ID
            String msgId = KHUtil.getRandomString(36);
            String datetime = dateFormat.format(new Date());
            String get36 = KHUtil.getRandomString(36);

            List chaxuncityList = eliteBean.chaxun_sql(" selecT CITY_ID,PROVINCE_ID from C_CITY where  RegEXP_LIKE(CITY_DESC,'" + city_id + "')  and rownum<=1", "dataSource");
            if (chaxuncityList.size() > 0) {
                cityCode = chaxuncityList.get(0).get("CITY_ID");  //城市
            }


            //请求报文
            xmljson = """<?xml version="1.0" encoding="UTF-8"?><request>
   <head><msgId>$msgId</msgId>
     <timeStamp>$datetime</timeStamp>
      <session>$get36</session><userCode>$customer_guid</userCode>
<clientName>$clientName</clientName></head><body>
      <sales>
            <cityCode>$cityCode</cityCode>
            <solutionCode></solutionCode>
            <applyNo></applyNo>
            <cooperateSiteCode></cooperateSiteCode>
            <groupNo></groupNo>
            <salesmanCode></salesmanCode>
        </sales>

<vehicle><frameNo>$frame_code</frameNo></vehicle></body>
</request>""";
            log.debug("【预评分】推送H5 V01请求报文:" + xmljson);

            //对报文进行加签
            byte[] signBytes;
            String respEncode = Base64.encode(xmljson.getBytes(defaultCharset));

            log.debug("respEncode:" + respEncode)
            signBytes = sign(respEncode.replace("\n", "").getBytes(), Base64.decode(privateKey), algorithm);
            String respSign = Base64.encode(signBytes, Integer.MAX_VALUE);

            log.debug("respSign:" + respSign);

            //设置请求表头
            Map<String, String> TokenParams = new HashMap<String, String>();
            TokenParams.put("TP-SIGN", respSign);
            //调用请求H5
            //postCallBackBody = Util.doHttpPostUseHead(String.format("%s/%s/%s", path, clientName, api), xmljson, "UTF-8", 60000, 0, TokenParams, "");
            postCallBackBody="A JSONObject text must begin with '{' at character 1 of";
            //模拟H5返回
            //   def postCallBackBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><head><msgId>c1480f3d-3580-4293-a0dd-8ef10653ab39</msgId><timeStamp>2017-12-18 10:18:46</timeStamp><session>b1870ca0-deac-4913-8e08-6e0b6f98af44</session><userCode>oeRlIuCu9HU4K-qIrVKahdof8XgQ</userCode><status>S</status></head><body><vehicle><carBrand>梅赛德斯-奔驰</carBrand><farmilyName>奔驰E级</farmilyName><exhaustScale>2.996</exhaustScale><purchasePrice>548000.00</purchasePrice><manualFlag>自动</manualFlag><configModel>奔驰BENZ E300轿车 2009款 2.996 BS02 548000.00元 5座</configModel><modelCode>BCI1385DGB</modelCode><printBrandName>行驶证厂牌型号</printBrandName><countryNature>国别性质</countryNature><seat>核定载客</seat><carYear>2023-11-30</carYear><vehicleCategory>2023-11-30</vehicleCategory><vehicleCategory>交管车辆类型</vehicleCategory><tonCount>31313</tonCount><fuelType>燃料种类</fuelType><energyType>能源种类</energyType><completeKerbMass>整备质量</completeKerbMass><carKindCodeShow>车辆种类</carKindCodeShow></vehicle></body></response>"
            log.debug("【预评分】推送H5 V01返回报文:" + postCallBackBody);




            if (!KHUtil.isNull(postCallBackBody)) {

                //转换成json
                String json = XML.toJSONObject(postCallBackBody);
                JSONObject jsonObject = JSONObject.fromObject(json);
                log.debug("【预评分】推送H5 V01 XML转换后返回的JSON报文：" + jsonObject.toString());
                String responseJson = GetJV(jsonObject, "response");

                JSONObject headjson = JSONObject.fromObject(responseJson);


                String headstrjson = GetJV(headjson, "head");

                JSONObject headjson2 = JSONObject.fromObject(headstrjson);


                status = GetJV(headjson2, "status");//返回报文标识    S/成功 F/失败
                String errCode = GetJV(headjson2, "errCode");//返回报文失败编码
                errMsg = GetJV(headjson2, "errMsg");//返回报文失败消息
                log.debug("【预评分】推送H5返回报文标识：" + status + "返回消息信息：" + errMsg);
                //解析body部分




                if (status.equals("S")) {
                    String bodyjsonstr = GetJV(headjson, "body");

                    JSONObject  bodyjson= JSONObject.fromObject(bodyjsonstr);
                    String delsql = '''DELETE FROM PUSH_H5_CARTYPE where CUSTOMER_GUID=?''';
                    jt.update(delsql, customer_guid);
                    //判断是否是JSonArr
                    Class<?> isArr = jsonObject.getJSONObject("response").getJSONObject("body").get("vehicle").getClass();
                    if (isArr.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr = bodyjson.getJSONArray("vehicle");
                        for (int i = 0; i < batcharr.size(); i++) {
                            JSONObject dataJson = batcharr.getJSONObject(i);
                            String carBrand = GetJV(dataJson, "carBrand");//品牌
                            String farmilyName = GetJV(dataJson, "farmilyName");//车系
                            String exhaustScale = GetJV(dataJson, "exhaustScale");//排量
                            String purchasePrice = GetJV(dataJson, "purchasePrice");//参考价
                            String manualFlag = GetJV(dataJson, "manualFlag");//手/自动档
                            String configModel = GetJV(dataJson, "configModel");//配置型号
                            String modelCode = GetJV(dataJson, "modelCode");//精有车型编码
                            String printBrandName = GetJV(dataJson, "printBrandName");//行驶证厂牌型号
                            String countryNature = GetJV(dataJson, "countryNature");//国别性质
                            String seat = GetJV(dataJson, "seat");//核定载客
                            String carYear = GetJV(dataJson, "carYear");//出厂日期
                            String vehicleCategory = GetJV(dataJson, "vehicleCategory");//交管车辆类型
                            String tonCount = GetJV(dataJson, "tonCount");//核定载质量
                            String fuelType = GetJV(dataJson, "fuelType");//燃料种类
                            String energyType = GetJV(dataJson, "energyType");//能源种类
                            String completeKerbMass = GetJV(dataJson, "completeKerbMass");//整备质量
                            String carKindCodeShow = GetJV(dataJson, "carKindCodeShow");//车辆种类
                            String insertsql =
                                    ''' 
                                   Insert
                                    into 
                                   PUSH_H5_CARTYPE
                                   (
                                   SYSID,
                                   FRAMENO,
                                   carBrand,
                                   farmilyName,
                                   exhaustScale,
                                   purchasePrice,
                                   manualFlag,
                                   configModel,
                                   modelCode,
                                   printBrandName,
                                   countryNature,
                                   seat,
                                   carYear,
                                   vehicleCategory,
                                   tonCount,
                                   fuelType,
                                   energyType,
                                   completeKerbMass,
                                   carKindCodeShow,
                                   CREATEDDATE,
                                   customer_guid
                                   )values(
                                   sysguid,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   sysdate,
                                   ?
                                   )
                                    ''';

                            jt.update(insertsql, frame_code, carBrand, farmilyName, exhaustScale, purchasePrice, manualFlag, configModel, modelCode, printBrandName, countryNature, seat, carYear, vehicleCategory, tonCount, fuelType, energyType, completeKerbMass, carKindCodeShow, customer_guid);
                        }
                    } else if (isArr.getName().equals("net.sf.json.JSONObject")) {
                        String vehiclebody = GetJV(bodyjson, "vehicle")
                        JSONObject batcharr = JSONObject.fromObject(vehiclebody);
                        String carBrand = GetJV(batcharr, "carBrand");//品牌
                        String farmilyName = GetJV(batcharr, "farmilyName");//车系
                        String exhaustScale = GetJV(batcharr, "exhaustScale");//排量
                        String purchasePrice = GetJV(batcharr, "purchasePrice");//参考价
                        String manualFlag = GetJV(batcharr, "manualFlag");//手/自动档
                        String configModel = GetJV(batcharr, "configModel");//配置型号
                        String modelCode = GetJV(batcharr, "modelCode");//精有车型编码
                        String printBrandName = GetJV(batcharr, "printBrandName");//行驶证厂牌型号
                        String countryNature = GetJV(batcharr, "countryNature");//国别性质
                        String seat = GetJV(batcharr, "seat");//核定载客
                        String carYear = GetJV(batcharr, "carYear");//出厂日期
                        String vehicleCategory = GetJV(batcharr, "vehicleCategory");//交管车辆类型
                        String tonCount = GetJV(batcharr, "tonCount");//核定载质量
                        String fuelType = GetJV(batcharr, "fuelType");//燃料种类
                        String energyType = GetJV(batcharr, "energyType");//能源种类
                        String completeKerbMass = GetJV(batcharr, "completeKerbMass");//整备质量
                        String carKindCodeShow = GetJV(batcharr, "carKindCodeShow");//车辆种类
                        String insertsql =
                                ''' 
                                   Insert
                                    into 
                                   PUSH_H5_CARTYPE
                                   (
                                   SYSID,
                                   FRAMENO,
                                   carBrand,
                                   farmilyName,
                                   exhaustScale,
                                   purchasePrice,
                                   manualFlag,
                                   configModel,
                                   modelCode,
                                   printBrandName,
                                   countryNature,
                                   seat,
                                   carYear,
                                   vehicleCategory,
                                   tonCount,
                                   fuelType,
                                   energyType,
                                   completeKerbMass,
                                   carKindCodeShow,
                                   CREATEDDATE,
                                   customer_guid
                                   )values(
                                   sysguid,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   ?,
                                   sysdate,
                                   ?
                                   )
                                    ''';

                        jt.update(insertsql, frame_code, carBrand, farmilyName, exhaustScale, purchasePrice, manualFlag, configModel, modelCode, printBrandName, countryNature, seat, carYear, vehicleCategory, tonCount, fuelType, energyType, completeKerbMass, carKindCodeShow, customer_guid);

                    }

                } else {
                    log.debug("【预评分】V01接口推送返回失败,将该条名单在标记为失败");
                    updatestate(eliteBean, customer_guid, xmljson.toString(), postCallBackBody.toString(),errMsg);
                }


            } else {
                log.debug("【预评分】V01接口推送返回失败,将该条名单在标记为失败");
                updatestate(eliteBean, customer_guid, xmljson.toString(), postCallBackBody.toString(),errMsg);
            }

        } catch (Exception e) {
            log.error("【预评分】V01接口推送H5异常：" + e.getMessage());
            updatestateXL(eliteBean, customer_guid, xmljson.toString(), e.getMessage(),e.getMessage());

        }
        return status.toString();
    }


    public static String push_h5_V02(EliteBean eliteBean, String frame_code, String customer_guid, String SERVICE_AREA, String city_id,String CREATEDGROUP,String isxb) {

        log.debug("【预评分】V02开始执行");


        String status = null;
        String defrequstInfo = null;
        String postCallBackBody = null;
        try {
            String clientName = KHDBConfig.getParam(eliteBean, "H5_SHH", "");//商户话哦
            String privateKey = KHDBConfig.getParam(eliteBean, "H5_KEY", "");//私钥
            String api = "saveOrderVehicle";
            JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());
            String sql = "select WEBSERVICEURL From sysc_interface where WEBTYPE='H5_URL'";
            List<Map<String, Object>> createlist = jt.queryForList(sql);
            String geturl = createlist.get(0).get("WEBSERVICEURL");
            String path = geturl + "/ecms2/portal";//地址

            String selectsql=null;
            log.debug("【预评分】请求地址：" + path);
            String H5SRT= KHDBConfig.getParam(eliteBean, "H5SRT", "");
            if (H5SRT.equals("ASC")) {
                selectsql = '''
                     select *from (  
                  select  T2.CUSTOMERNAME,T2.CUSTOMERID,T1.CAR_PLATE,T1.FRAME_CODE,t1.ENGINE_CODE,h5.MODELCODE,to_char(T1.IN_STARTDATE, 'YYYY-mm-dd') as IN_STARTDATE,T1.IN_ENDDATE from customer T1
                       Left join Customer T2  On T2.Customer_Guid = T1.Parent_Guid
                       Left join push_h5_cartype  h5 on h5.customer_guid=T1.Customer_Guid 
                       WHERE T1.customer_guid=?
                            order by h5.PURCHASEPRICE asc
                    )      where  rownum <=1
                       ''';

            }else {

                selectsql = '''
                     select *from (  
                  select  T2.CUSTOMERNAME,T2.CUSTOMERID,T1.CAR_PLATE,T1.FRAME_CODE,t1.ENGINE_CODE,h5.MODELCODE,to_char(T1.IN_STARTDATE, 'YYYY-mm-dd') as IN_STARTDATE,T1.IN_ENDDATE from customer T1
                       Left join Customer T2  On T2.Customer_Guid = T1.Parent_Guid
                       Left join push_h5_cartype  h5 on h5.customer_guid=T1.Customer_Guid 
                       WHERE T1.customer_guid=?
                            order by h5.PURCHASEPRICE desc
                    )      where  rownum <=1
                       ''';
            }
            List<Map<String, Object>> chaxunList = jt.queryForList(selectsql, customer_guid);
            Map chaxunListMap = chaxunList.get(0);

            String customername = chaxunListMap.get("CUSTOMERNAME");//客户姓名
            String CUSTOMERID = chaxunListMap.get("CUSTOMERID");   //身份证号
            String CAR_PLATE = chaxunListMap.get("CAR_PLATE");   //车牌号
            String FRAME_CODE = chaxunListMap.get("FRAME_CODE");  //车架号
            String ENGINE_CODE = chaxunListMap.get("ENGINE_CODE");  //发动机号
            String MODELCODE = chaxunListMap.get("MODELCODE");    //精友车型编码
            String IN_STARTDATE = chaxunListMap.get("IN_STARTDATE");    //保险起期
            String IN_ENDDATE = chaxunListMap.get("IN_ENDDATE");    //保险止期


            Date date = new Date();
            //消息ID
            String msgId = KHUtil.getRandomString(36);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            String datetime = dateFormat.format(new Date());
            String get36 = KHUtil.getRandomString(36);

            String cityCode = null;//城市代码
            String applyNo = null;//决策单元
            String PROVINCE_ID = null;//省份ID
            String PROVINCE_DESC = null;//省份名称
            String THRIN_RISK = null;//三者险
            String DRIVER_RISK = null;//司机险
            String PASSENGER_RISK = null;//乘客险
            String configcustomerid=null;//配置的身份证号
            //查找城市代码

            List chaxuncityList = eliteBean.chaxun_sql(" selecT CITY_ID,PROVINCE_ID from C_CITY where  RegEXP_LIKE(CITY_DESC,'" + city_id + "')  and rownum<=1", "dataSource");
            if (chaxuncityList.size() > 0) {
                cityCode = chaxuncityList.get(0).get("CITY_ID");  //城市
                PROVINCE_ID = chaxuncityList.get(0).get("PROVINCE_ID");  //省份ID
                //查找省份代码
                List chaxunPROVINCEList = eliteBean.chaxun_sql(" selecT PROVINCE_DESC from C_PROVINCE where PROVINCE_ID = '" + PROVINCE_ID + "' and rownum<=1", "dataSource");

                if (chaxunPROVINCEList.size() > 0) {
                    PROVINCE_DESC = chaxunPROVINCEList.get(0).get("PROVINCE_DESC")
                    //查询预评分销售信息配置表

                    String ypfsalaSQl=null;

                    //2是非续保
                    if(isxb.equals("2")){

                        ypfsalaSQl=" selecT THRIN_RISK,DRIVER_RISK,PASSENGER_RISK,DECISION,CUSTOMERID from push_h5_sale_config where RegEXP_LIKE(TWO_ORGANIZATION,'" + PROVINCE_DESC + "') and  RegEXP_LIKE(THREE_ORGANIZATION,'" + city_id + "')  AND (isxb!='1' or isxb is null )   and ROLEGROUP_ID='"+CREATEDGROUP+"' and rownum<=1";

                    }else{

                        ypfsalaSQl=" selecT THRIN_RISK,DRIVER_RISK,PASSENGER_RISK,DECISION,CUSTOMERID from push_h5_sale_config where RegEXP_LIKE(TWO_ORGANIZATION,'" + PROVINCE_DESC + "') and  RegEXP_LIKE(THREE_ORGANIZATION,'" + city_id + "')  AND isxb='1'    and ROLEGROUP_ID='"+CREATEDGROUP+"' and rownum<=1";

                    }


                    List ypfsalaList = eliteBean.chaxun_sql(ypfsalaSQl, "dataSource");
                    if (ypfsalaList.size() > 0) {
                        THRIN_RISK = ypfsalaList.get(0).get("THRIN_RISK");//三者险
                        DRIVER_RISK = ypfsalaList.get(0).get("DRIVER_RISK");//司机险
                        PASSENGER_RISK = ypfsalaList.get(0).get("PASSENGER_RISK");//乘客险
                        applyNo = ypfsalaList.get(0).get("DECISION");//决策单元
                        configcustomerid= ypfsalaList.get(0).get("CUSTOMERID");//身份证号
                    } else {
                        //没匹配到用其他兜底销售信息
                        List qtypfsalaList = eliteBean.chaxun_sql(" selecT THRIN_RISK,DRIVER_RISK,PASSENGER_RISK,DECISION,CUSTOMERID from push_h5_sale_config where TWO_ORGANIZATION='其他' and ROLEGROUP_ID is null   and rownum<=1", "dataSource");
                        if (qtypfsalaList.size() > 0) {
                            THRIN_RISK = qtypfsalaList.get(0).get("THRIN_RISK");//三者险
                            DRIVER_RISK = qtypfsalaList.get(0).get("DRIVER_RISK");//司机险
                            PASSENGER_RISK = qtypfsalaList.get(0).get("PASSENGER_RISK");//乘客险
                            applyNo = qtypfsalaList.get(0).get("DECISION");//决策单元
                            configcustomerid= qtypfsalaList.get(0).get("CUSTOMERID");//身份证号


                        }
                    }


                }
                //如果身份证为空用配置的身份证号
                if (KHUtil.isNull(CUSTOMERID)){

                    CUSTOMERID=configcustomerid;
                }

                if (KHUtil.isNull(CAR_PLATE)){

                    CAR_PLATE="暂未上牌";
                }




                defrequstInfo = """<?xml version="1.0" encoding="UTF-8"?><request><head><msgId>$msgId</msgId><timeStamp>$datetime</timeStamp><session>$get36</session><userCode>$customer_guid</userCode><clientName>$clientName</clientName></head><body><order><orderNo></orderNo></order><sales><cityCode>$cityCode</cityCode><solutionCode></solutionCode><applyNo>$applyNo</applyNo><cooperateSiteCode>$SERVICE_AREA</cooperateSiteCode><groupNo></groupNo><salesmanCode></salesmanCode></sales><carOwner><name>$customername</name><identifyNumber>$CUSTOMERID</identifyNumber></carOwner><vehicle> <singeinDate>$IN_STARTDATE</singeinDate><chgOwnerFlag>0</chgOwnerFlag><licenseNo>$CAR_PLATE</licenseNo><frameNo>$FRAME_CODE</frameNo><engineNo>$ENGINE_CODE</engineNo><modelCode>$MODELCODE</modelCode></vehicle></body></request>""";
                log.debug("【预评分】推送H5 V02请求报文:" + defrequstInfo);
                //对报文进行加签
                byte[] signBytes;
                String respEncode = Base64.encode(defrequstInfo.getBytes(defaultCharset));
                signBytes = sign(respEncode.replace("\n", "").getBytes(), Base64.decode(privateKey), algorithm);
                String respSign = Base64.encode(signBytes, Integer.MAX_VALUE);
                //越过SSL验证
                SSLContext ctx = SSLContext.getInstance("TLS");
                SSLContext.setDefault(ctx);

                //设置请求表头
                Map<String, String> TokenParams = new HashMap<String, String>();
                TokenParams.put("TP-SIGN", respSign);
                //调用请求H5
                postCallBackBody = Util.doHttpPostUseHead(String.format("%s/%s/%s", path, clientName, api), defrequstInfo, "UTF-8", 60000, 0, TokenParams, "");

                //模拟H5返回
                //  def postCallBackBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><head><msgId>c1480f3d-3580-4293-a0dd-8ef10653ab39</msgId><timeStamp>2017-12-18 10:18:46</timeStamp><session>b1870ca0-deac-4913-8e08-6e0b6f98af44</session><userCode>oeRlIuCu9HU4K-qIrVKahdof8XgQ</userCode><clientName>H007001</clientName><status>S</status></head><body><order><orderNo>f80c10f1-587c-403f-ab21-96df60ccc069</orderNo></order></body></response>"
                log.debug("【预评分】推送H5 V02返回报文:" + postCallBackBody);
                def xmlstr = Util.Transform(postCallBackBody);
                def LIST = new XmlParser().parseText(xmlstr);

                status = LIST.head.status.text();//返回报文标识    S/成功 F/失败
                String errCode = LIST.head.errCode.text();//返回报文失败编码
                String errMsg = LIST.head.errMsg.text();//返回报文失败消息
                String orderNo = LIST.body.order.orderNo.text();//订单号
                String suitClause = LIST.body.order.suitClause.text();//适用条款

                if (status.equals("S")) {
                    //更新订单号
                    String updatesql = '''update push_h5_cartype set ORDERNO=?,suitClause=?   where customer_guid=?''';
                    jt.update(updatesql, orderNo,suitClause, customer_guid);
                } else {
                    log.debug("【预评分】V02接口推送返回失败,将该条名单在标记为失败");
                    updatestate(eliteBean, customer_guid, defrequstInfo.toString(), postCallBackBody.toString(),errMsg);
                }
            } else {
                //城市信息找不到失败
                updatestate(eliteBean, customer_guid, "城市信息找不到", "城市信息找不到", "城市信息找不到");
            }


        } catch (Exception e) {
            log.error("【预评分】V02接口推送H5异常：" + e.getMessage());

            updatestateXL(eliteBean, customer_guid, defrequstInfo.toString(), e.getMessage(), e.getMessage());
        }

        return status.toString();
    }

    public static String push_h5_V03(EliteBean eliteBean, String frame_code, String customer_guid, String SERVICE_AREA, String city_id,String CREATEDGROUP,String  isxb) {

        log.debug("【预评分】V03开始执行");
        String defrequstInfo = null;
        String postCallBackBody = null;
        String status = null;//状态标识
        try {


            String clientName = KHDBConfig.getParam(eliteBean, "H5_SHH", "");//商户话哦
            String privateKey = KHDBConfig.getParam(eliteBean, "H5_KEY", "");//私钥
            String api = "premiumCalculate";
            JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());
            String sql = "select WEBSERVICEURL From sysc_interface where WEBTYPE='H5_URL'";
            List<Map<String, Object>> createlist = jt.queryForList(sql);
            String geturl = createlist.get(0).get("WEBSERVICEURL");
            String path = geturl + "/ecms2/portal";//地址

            String selectsql=null;
            log.debug("【预评分】请求地址：" + path);
            String H5SRT= KHDBConfig.getParam(eliteBean, "H5SRT", "");
            if (H5SRT.equals("ASC")){
                selectsql = '''
                  select *from (  
                  select T2.CUSTOMERNAME,T2.CUSTOMERID,T1.CAR_PLATE,T1.FRAME_CODE,t1.ENGINE_CODE,h5.MODELCODE,to_date(to_char(sysdate+1,'YYYY-MM-DD') ||'00:00:00','yyyy-mm-dd hh24:mi:ss') as BXQQ,case
                          when T1.ADDRESS is not null then T1.ADDRESS WHEN T1.ADDRESS1 is not null then  T1.ADDRESS1 
                          WHEN T1.ADDRESS2 is not null  THEN T2.ADDRESS2   end as ADDRESS,T2.MOBILE,to_char(T1.IN_STARTDATE, 'YYYY-mm-dd hh24:mm:ss')  AS IN_STARTDATE ,
                       to_date(to_char(add_months(sysdate,1*12),'YYYY-MM-DD')||'23:59:59','yyyy-mm-dd hh24:mi:ss')  AS  IN_ENDDATE,h5.ORDERNO,h5.ENERGYTYPE,h5.suitClause from customer T1
                       Left join Customer T2  On T2.Customer_Guid = T1.Parent_Guid
                       Left join push_h5_cartype  h5 on h5.customer_guid=T1.Customer_Guid 
                       WHERE T1.customer_guid=?
                           order by h5.PURCHASEPRICE ASC
                       )        where  rownum <=1
                       ''';

            }else{

                selectsql = '''
                  select *from (  
                  select T2.CUSTOMERNAME,T2.CUSTOMERID,T1.CAR_PLATE,T1.FRAME_CODE,t1.ENGINE_CODE,h5.MODELCODE,to_date(to_char(sysdate+1,'YYYY-MM-DD') ||'00:00:00','yyyy-mm-dd hh24:mi:ss') as BXQQ,case
                          when T1.ADDRESS is not null then T1.ADDRESS WHEN T1.ADDRESS1 is not null then  T1.ADDRESS1 
                          WHEN T1.ADDRESS2 is not null  THEN T2.ADDRESS2   end as ADDRESS,T2.MOBILE,to_char(T1.IN_STARTDATE, 'YYYY-mm-dd hh24:mm:ss')  AS IN_STARTDATE ,
                       to_date(to_char(add_months(sysdate,1*12),'YYYY-MM-DD')||'23:59:59','yyyy-mm-dd hh24:mi:ss')  AS  IN_ENDDATE,h5.ORDERNO,h5.ENERGYTYPE,h5.suitClause
                       from customer T1
                       Left join Customer T2  On T2.Customer_Guid = T1.Parent_Guid
                       Left join push_h5_cartype  h5 on h5.customer_guid=T1.Customer_Guid 
                       WHERE T1.customer_guid=?
                           order by h5.PURCHASEPRICE DESC
                       )        where  rownum <=1
                       ''';

            }
            List<Map<String, Object>> chaxunList = jt.queryForList(selectsql, customer_guid);
            String customername = chaxunList.get(0).get("CUSTOMERNAME");//客户姓名
            String CUSTOMERID = chaxunList.get(0).get("CUSTOMERID");   //身份证号
            String MOBILE = chaxunList.get(0).get("MOBILE");   //手机号
            String ADDRESS = chaxunList.get(0).get("ADDRESS");   //地址
            String CAR_PLATE = chaxunList.get(0).get("CAR_PLATE");   //车牌号
            String FRAME_CODE = chaxunList.get(0).get("FRAME_CODE");  //车架号
            String ENGINE_CODE = chaxunList.get(0).get("ENGINE_CODE");  //发动机号
            String MODELCODE = chaxunList.get(0).get("MODELCODE");    //精友车型编码
            String IN_STARTDATE = chaxunList.get(0).get("IN_STARTDATE");    //保险起期
            String IN_ENDDATE = chaxunList.get(0).get("IN_ENDDATE");    //保险止期
            String ORDERNO = chaxunList.get(0).get("ORDERNO");    //订单
            String ENERGYTYPE = chaxunList.get(0).get("ENERGYTYPE");    //车辆标识  0是油  1是电suitClause
            String suitClause2 = chaxunList.get(0).get("suitClause");    //适用条款  1: 20年机动车条款；2 :新能源条款
            String BXQQ = chaxunList.get(0).get("BXQQ").toString();    //保险起期
            Date date = new Date();
            //消息ID
            String msgId = KHUtil.getRandomString(36);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String datetime = dateFormat.format(new Date());
            String get36 = KHUtil.getRandomString(36);

            Date date1= null;//保险起期
            Date date2= null;//保险止期

            date1=dateFormat.parse(BXQQ);
            date2=dateFormat.parse(IN_ENDDATE);

            String date3=dateFormat.format(date1);
            String date4=dateFormat.format(date2);

            String cityCode = null;//城市代码
            String applyNo = null;//决策单元
            String PROVINCE_ID = null;//省份ID
            String PROVINCE_DESC = null;//省份名称
            String THRIN_RISK = null;//三者险
            String DRIVER_RISK = null;//司机险
            String PASSENGER_RISK = null;//乘客险
            String configcustomerid=null;//配置的身份证号
            String SYSID=null;//配置表guid
            String isylx =null;//是否搭售医疗险
            //查找城市代码
            List chaxuncityList = eliteBean.chaxun_sql(" selecT CITY_ID,PROVINCE_ID from C_CITY where  RegEXP_LIKE(CITY_DESC,'" + city_id + "')  and rownum<=1", "dataSource");
            if (chaxuncityList.size() > 0) {
                cityCode = chaxuncityList.get(0).get("CITY_ID");  //城市
                PROVINCE_ID = chaxuncityList.get(0).get("PROVINCE_ID");  //省份ID

                //查找省份代码
                List chaxunPROVINCEList = eliteBean.chaxun_sql(" selecT PROVINCE_DESC from C_PROVINCE where PROVINCE_ID = '" + PROVINCE_ID + "' and rownum<=1", "dataSource");

                if (chaxunPROVINCEList.size() > 0) {
                    PROVINCE_DESC = chaxunPROVINCEList.get(0).get("PROVINCE_DESC")
                    String ypfsalaSQl=null;
                    //2是非续保
                    if(isxb.equals("2")){

                        ypfsalaSQl=" selecT SYSID,THRIN_RISK,DRIVER_RISK,PASSENGER_RISK,DECISION,CUSTOMERID,isylx from push_h5_sale_config where RegEXP_LIKE(TWO_ORGANIZATION,'" + PROVINCE_DESC + "') and  RegEXP_LIKE(THREE_ORGANIZATION,'" + city_id + "')  AND (isxb!='1' or isxb is null ) and ROLEGROUP_ID='"+CREATEDGROUP+"' and rownum<=1";

                    }else{

                        ypfsalaSQl=" selecT SYSID,THRIN_RISK,DRIVER_RISK,PASSENGER_RISK,DECISION,CUSTOMERID,isylx from push_h5_sale_config where RegEXP_LIKE(TWO_ORGANIZATION,'" + PROVINCE_DESC + "') and  RegEXP_LIKE(THREE_ORGANIZATION,'" + city_id + "')  AND isxb='1' and ROLEGROUP_ID='"+CREATEDGROUP+"' and rownum<=1";

                    }

                    //查询预评分销售信息配置表
                    List ypfsalaList = eliteBean.chaxun_sql(ypfsalaSQl, "dataSource");
                    if (ypfsalaList.size() > 0) {
                        THRIN_RISK = ypfsalaList.get(0).get("THRIN_RISK");//三者险
                        DRIVER_RISK = ypfsalaList.get(0).get("DRIVER_RISK");//司机险
                        PASSENGER_RISK = ypfsalaList.get(0).get("PASSENGER_RISK");//乘客险
                        applyNo = ypfsalaList.get(0).get("DECISION");//决策单元
                        configcustomerid= ypfsalaList.get(0).get("CUSTOMERID");//身份证号
                        SYSID= ypfsalaList.get(0).get("SYSID");//身份证号
                        isylx= ypfsalaList.get(0).get("isylx");//是否搭售医疗险  1.是搭售,其他不搭售
                    } else {
                        //没匹配到用其他兜底销售信息
                        List qtypfsalaList = eliteBean.chaxun_sql(" selecT  SYSID,THRIN_RISK,DRIVER_RISK,PASSENGER_RISK,DECISION,CUSTOMERID from push_h5_sale_config where TWO_ORGANIZATION='其他' and ROLEGROUP_ID is null and rownum<=1", "dataSource");
                        if (qtypfsalaList.size() > 0) {
                            THRIN_RISK = qtypfsalaList.get(0).get("THRIN_RISK");//三者险
                            DRIVER_RISK = qtypfsalaList.get(0).get("DRIVER_RISK");//司机险
                            PASSENGER_RISK = qtypfsalaList.get(0).get("PASSENGER_RISK");//乘客险
                            applyNo = qtypfsalaList.get(0).get("DECISION");//决策单元
                            configcustomerid= qtypfsalaList.get(0).get("CUSTOMERID");//身份证号是
                            SYSID= qtypfsalaList.get(0).get("SYSID");//身份证号

                        }
                    }


                }





                //如果身份证为空用配置的身份证号
                if (KHUtil.isNull(CUSTOMERID)){

                    CUSTOMERID=configcustomerid;
                }

                if (suitClause2.equals("2")){

                    if (isylx.equals("1")){
                        defrequstInfo = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<request>
    <head>
        <msgId>$msgId</msgId>
        <timeStamp>$datetime</timeStamp>
        <userCode>$customer_guid</userCode>
        <clientName>$clientName</clientName>
    </head>
    <body>
        <order>
            <orderNo>$ORDERNO</orderNo>
        </order>
        <sales>
            <cityCode>$cityCode</cityCode>
            <solutionCode></solutionCode>
            <applyNo>$applyNo</applyNo>
            <cooperateSiteCode>$SERVICE_AREA</cooperateSiteCode>
            <groupNo></groupNo>
            <salesmanCode></salesmanCode>
        </sales>
        <risk>
          <startDate>$date3</startDate>
             <endDate>$date4</endDate>
            <riskCode>BS</riskCode>
            <effectFlag>0</effectFlag>
        </risk>
        <itemKindBS>
            <kindCode>0401600</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$THRIN_RISK</insured>
        </itemKindBS>
            <itemKindBS>
            <kindCode>0401701</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$DRIVER_RISK</insured>           
        </itemKindBS>
            <itemKindBS>
            <kindCode>0401702</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$PASSENGER_RISK</insured> 
        </itemKindBS>
             <itemKindBS>
            <kindCode>0301002</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$THRIN_RISK</insured>
            <shareModel>1</shareModel>
        </itemKindBS>
                <itemKindBS>
            <kindCode>0301011</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$DRIVER_RISK</insured>
            <shareModel>1</shareModel>
        </itemKindBS>
               <itemKindBS>
            <kindCode>0301012</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$PASSENGER_RISK</insured>
            <shareModel>1</shareModel>
        </itemKindBS>
        <applicant>
            <appliName>$customername</appliName>
            <identifyNumber>$CUSTOMERID</identifyNumber>
            <mobilePhone>$MOBILE</mobilePhone>
            <appliAddress>$ADDRESS</appliAddress>
        </applicant>
        <insured>
            <insuredName>$customername</insuredName>
            <identifyNumber>$CUSTOMERID</identifyNumber>
            <insuredMobilePhone>$MOBILE</insuredMobilePhone>
            <insuredAddress>$ADDRESS</insuredAddress>
        </insured>
        <vehicle>
         </vehicle>
    </body>
</request>
                             """;
                    }else{
                        defrequstInfo = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<request>
    <head>
        <msgId>$msgId</msgId>
        <timeStamp>$datetime</timeStamp>
        <userCode>$customer_guid</userCode>
        <clientName>$clientName</clientName>
    </head>
    <body>
        <order>
            <orderNo>$ORDERNO</orderNo>
        </order>
        <sales>
            <cityCode>$cityCode</cityCode>
            <solutionCode></solutionCode>
            <applyNo>$applyNo</applyNo>
            <cooperateSiteCode>$SERVICE_AREA</cooperateSiteCode>
            <groupNo></groupNo>
            <salesmanCode></salesmanCode>
        </sales>
        <risk>
          <startDate>$date3</startDate>
             <endDate>$date4</endDate>
            <riskCode>BS</riskCode>
            <effectFlag>0</effectFlag>
        </risk>
        <itemKindBS>
            <kindCode>0401600</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$THRIN_RISK</insured> 
        </itemKindBS>
            <itemKindBS>
            <kindCode>0401701</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$DRIVER_RISK</insured> 
        </itemKindBS>
            <itemKindBS>
            <kindCode>0401702</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$PASSENGER_RISK</insured> 
        </itemKindBS>
        <applicant>
            <appliName>$customername</appliName>
            <identifyNumber>$CUSTOMERID</identifyNumber>
            <mobilePhone>$MOBILE</mobilePhone>
            <appliAddress>$ADDRESS</appliAddress>
        </applicant>
        <insured>
            <insuredName>$customername</insuredName>
            <identifyNumber>$CUSTOMERID</identifyNumber>
            <insuredMobilePhone>$MOBILE</insuredMobilePhone>
            <insuredAddress>$ADDRESS</insuredAddress>
        </insured>
        <vehicle>
         </vehicle>
    </body>
</request>
                             """;
                    }


                }else{

                    if (isylx.equals("1")){
                        defrequstInfo = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<request>
    <head>
        <msgId>$msgId</msgId>
        <timeStamp>$datetime</timeStamp>
        <userCode>$customer_guid</userCode>
        <clientName>$clientName</clientName>
    </head>
    <body>
        <order>
            <orderNo>$ORDERNO</orderNo>
        </order>
        <sales>
            <cityCode>$cityCode</cityCode>
            <solutionCode></solutionCode>
            <applyNo>$applyNo</applyNo>
            <cooperateSiteCode>$SERVICE_AREA</cooperateSiteCode>
            <groupNo></groupNo>
            <salesmanCode></salesmanCode>
        </sales>
        <risk>
            <startDate>$date3</startDate>
             <endDate>$date4</endDate>
            <riskCode>BS</riskCode>
            <effectFlag>0</effectFlag>
        </risk>
        <itemKindBS>
            <kindCode>0301600</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$THRIN_RISK</insured>
        </itemKindBS>
            <itemKindBS>
            <kindCode>0301701</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$DRIVER_RISK</insured>
        </itemKindBS>
            <itemKindBS>
            <kindCode>0301702</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$PASSENGER_RISK</insured>
        </itemKindBS>
             <itemKindBS>
            <kindCode>0301002</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$THRIN_RISK</insured>
            <shareModel>1</shareModel> 
        </itemKindBS>
                <itemKindBS>
            <kindCode>0301011</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$DRIVER_RISK</insured>
            <shareModel>1</shareModel> 
        </itemKindBS>
               <itemKindBS>
            <kindCode>0301012</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$PASSENGER_RISK</insured>
            <shareModel>1</shareModel> 
        </itemKindBS>
        <applicant>
            <appliName>$customername</appliName>
            <identifyNumber>$CUSTOMERID</identifyNumber>
            <mobilePhone>$MOBILE</mobilePhone>
            <appliAddress>$ADDRESS</appliAddress>
        </applicant>
        <insured>
            <insuredName>$customername</insuredName>
            <identifyNumber>$CUSTOMERID</identifyNumber>
            <insuredMobilePhone>$MOBILE</insuredMobilePhone>
            <insuredAddress>$ADDRESS</insuredAddress>
        </insured>
        <vehicle>
         </vehicle>
    </body>
</request>
                             """;
                    }else{
                        defrequstInfo = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<request>
    <head>
        <msgId>$msgId</msgId>
        <timeStamp>$datetime</timeStamp>
        <userCode>$customer_guid</userCode>
        <clientName>$clientName</clientName>
    </head>
    <body>
        <order>
            <orderNo>$ORDERNO</orderNo>
        </order>
        <sales>
            <cityCode>$cityCode</cityCode>
            <solutionCode></solutionCode>
            <applyNo>$applyNo</applyNo>
            <cooperateSiteCode>$SERVICE_AREA</cooperateSiteCode>
            <groupNo></groupNo>
            <salesmanCode></salesmanCode>
        </sales>
        <risk>
            <startDate>$date3</startDate>
             <endDate>$date4</endDate>
            <riskCode>BS</riskCode>
            <effectFlag>0</effectFlag>
        </risk>
        <itemKindBS>
            <kindCode>0301600</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$THRIN_RISK</insured> 
        </itemKindBS>
            <itemKindBS>
            <kindCode>0301701</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$DRIVER_RISK</insured> 
        </itemKindBS>
            <itemKindBS>
            <kindCode>0301702</kindCode>
            <relatedInd>1</relatedInd>
            <insured>$PASSENGER_RISK</insured> 
        </itemKindBS>
        <applicant>
            <appliName>$customername</appliName>
            <identifyNumber>$CUSTOMERID</identifyNumber>
            <mobilePhone>$MOBILE</mobilePhone>
            <appliAddress>$ADDRESS</appliAddress>
        </applicant>
        <insured>
            <insuredName>$customername</insuredName>
            <identifyNumber>$CUSTOMERID</identifyNumber>
            <insuredMobilePhone>$MOBILE</insuredMobilePhone>
            <insuredAddress>$ADDRESS</insuredAddress>
        </insured>
        <vehicle>
         </vehicle>
    </body>
</request>
                             """;

                    }

                }


                log.debug("【预评分】推送H5 V03请求报文:" + defrequstInfo);

                //对报文进行加签
                byte[] signBytes;
                String respEncode = Base64.encode(defrequstInfo.getBytes(defaultCharset));
                signBytes = sign(respEncode.replace("\n", "").getBytes(), Base64.decode(privateKey), algorithm);
                String respSign = Base64.encode(signBytes, Integer.MAX_VALUE);

                //设置请求表头
                Map<String, String> TokenParams = new HashMap<String, String>();
                TokenParams.put("TP-SIGN", respSign);
                //调用请求H5
                postCallBackBody = Util.doHttpPostUseHead(String.format("%s/%s/%s", path, clientName, api), defrequstInfo.toString(), "UTF-8", 60000, 0, TokenParams, "");
                //模拟H5返回
                //  def postCallBackBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><head><msgId>c1480f3d-3580-4293-a0dd-8ef10653ab39</msgId><timeStamp>2017-12-18 10:18:46</timeStamp><session>b1870ca0-deac-4913-8e08-6e0b6f98af44</session><userCode>oeRlIuCu9HU4K-qIrVKahdof8XgQ</userCode><clientName>H007001</clientName><status>S</status></head><body><order><orderNo>f80c10f1-587c-403f-ab21-96df60ccc069</orderNo></order></body></response>"
                log.debug("【预评分】推送H5 V03返回报文:" + postCallBackBody);
                //转换成json
                String json = XML.toJSONObject(postCallBackBody);

                JSONObject jsonObject = JSONObject.fromObject(json);

                log.debug("【预评分】推送H5 V03 XML转换后返回的JSON报文：" + jsonObject.toString());


                String responseJson = GetJV(jsonObject, "response");

                JSONObject headjson = JSONObject.fromObject(responseJson);


                String headstrjson = GetJV(headjson, "head");

                JSONObject headjson2 = JSONObject.fromObject(headstrjson);


                status = GetJV(headjson2, "status");//返回报文标识    S/成功 F/失败
                String errCode = GetJV(headjson2, "errCode");//返回报文失败编码
                String errMsg = GetJV(headjson2, "errMsg");//返回报文失败消息

                if (status.equals("S")) {
                    String body = GetJV(headjson, "body");
                    JSONObject bodyjson = JSONObject.fromObject(body);
                    log.debug("扩展信息")
                    //扩展信息

                    String linkedFlag = Get
                    String premiumTrialFlag = null;
                    String tpFlag = null;
                    String xzxId = null;
                    String discountDown = null;
                    String discountUp = null;
                    String ncd = null;
                    String extend = GetJV(bodyjson, "extend");
                    if (!KHUtil.isNull(extend)) {
                        JSONObject extendjson = JSONObject.fromObject(extend);
                        linkedFlag = GetJV(extendjson, "linkedFlag");//能否价费联动
                        premiumTrialFlag = GetJV(extendjson, "premiumTrialFlag");//保费试算标识
                        tpFlag = GetJV(extendjson, "tpFlag");//能否进行特批标识
                        xzxId = GetJV(extendjson, "xzxId");//新转续标识
                        discountDown = GetJV(extendjson, "discountDown");//折扣下限
                        discountUp = GetJV(extendjson, "discountUp");//折扣上限
                        ncd = GetJV(extendjson, "ncd");//?
                    }
                    log.debug("车主信息")
                    //车主信息
                    String carOwner = GetJV(bodyjson, "carOwner");
                    JSONObject carOwnerjson = JSONObject.fromObject(carOwner);
                    String name = GetJV(carOwnerjson, "name");//车主名称
                    String identifyNumber = GetJV(carOwnerjson, "identifyNumber");//证件号
                    String ownerNature = GetJV(carOwnerjson, "ownerNature");//车主性质
                    String identifyType = GetJV(carOwnerjson, "identifyType");//车主证件类型
                    String birthDate = GetJV(carOwnerjson, "birthDate");//生日
                    String sex = GetJV(carOwnerjson, "sex");//性别


                    String demandNo = null;
                    String registerNo = null;
                    String lossTime = null;
                    String endCaseTime = null;
                    String lossFee = null;
                    String claimNotificationNo = null;
                    String accidentDeathFlag = null;
                    String policyNo = null;

                    log.debug("出险理赔信息");
                    //出险理赔信息
                    String demandPay = GetJV(bodyjson, "demandPay");
                    if (!KHUtil.isNull(demandPay)) {
                        JSONObject demandPayjson = JSONObject.fromObject(demandPay);
                        demandNo = GetJV(demandPayjson, "demandNo");//查询码
                        registerNo = GetJV(demandPayjson, "registerNo");//立案号
                        lossTime = GetJV(demandPayjson, "lossTime");//出险时间
                        endCaseTime = GetJV(demandPayjson, "endCaseTime");//结案时间
                        lossFee = GetJV(demandPayjson, "lossFee");//赔付金额
                        claimNotificationNo = GetJV(demandPayjson, "claimNotificationNo");//理赔编码
                        accidentDeathFlag = GetJV(demandPayjson, "accidentDeathFlag");//是否发生有责任交通死亡事
                        policyNo = GetJV(demandPayjson, "policyNo");//保单号

                    }

                    log.debug("车辆信息")
                    //车辆信息
                    String vehicle = GetJV(bodyjson, "vehicle");

                    String carCheckStatus =null;
                    String brandName = null;
                    String licenseNo = null;
                    String frameNo = null;
                    String engineNo = null;
                    String chgOwnerFlag =null;
                    String transferDate = null;
                    String bschgOwnerFlag = null;
                    String bzchgOwnerFlag =null;
                    String singeinDate =null;
                    String certificateDate =null;
                    String seatCount = null;
                    String loanVehicleFlag =null;
                    String negotiatedActualValue=null;
                    String actualValue =null;
                    String carKindCode =null;
                    String purchasePrice=null;
                    String ciModelCode =null;
                    String ciModelName =null;
                    String carUseType =null;
                    String attachNature=null;
                    String useNatureShow =null;
                    String driveUseAttribute=null;
                    String licenseColorCode =null;
                    String enrollDate =null;
                    String completeKerbMass=null;
                    String vehicleCategory=null;
                    String energyType =null;
                    String suitClause=null;

                    if (!KHUtil.isNull(vehicle)) {


                        JSONObject vehiclejson = JSONObject.fromObject(vehicle);
                        carCheckStatus = GetJV(vehiclejson, "carCheckStatus");//验车情况
                        brandName = GetJV(vehiclejson, "brandName");//品牌型号
                        licenseNo = GetJV(vehiclejson, "licenseNo");//车牌号
                        frameNo = GetJV(vehiclejson, "frameNo");//车架号
                        engineNo = GetJV(vehiclejson, "engineNo");//发动机号
                        chgOwnerFlag = GetJV(vehiclejson, "chgOwnerFlag");//是否过户车
                        transferDate = GetJV(vehiclejson, "transferDate");//过户日期
                        bschgOwnerFlag = GetJV(vehiclejson, "bschgOwnerFlag");//商业过户车标识
                        bzchgOwnerFlag = GetJV(vehiclejson, "bzchgOwnerFlag");//交强过户车标识
                        singeinDate = GetJV(vehiclejson, "singeinDate");//登记日期
                        certificateDate = GetJV(vehiclejson, "certificateDate");//发证日期
                        seatCount = GetJV(vehiclejson, "seatCount");//座位数
                        loanVehicleFlag = GetJV(vehiclejson, "loanVehicleFlag");//是否贷款车
                        negotiatedActualValue = GetJV(vehiclejson, "negotiatedActualValue");//协商实际价值
                        actualValue = GetJV(vehiclejson, "actualValue");//实际价值
                        carKindCode = GetJV(vehiclejson, "carKindCode");//车辆种类
                        purchasePrice = GetJV(vehiclejson, "purchasePrice");//新车购置价
                        ciModelCode = GetJV(vehiclejson, "ciModelCode");//行业车型编码
                        ciModelName = GetJV(vehiclejson, "ciModelName");//行业车型名称
                        carUseType = GetJV(vehiclejson, "carUseType");//车辆用途
                        attachNature = GetJV(vehiclejson, "attachNature");//所属性质
                        useNatureShow = GetJV(vehiclejson, "useNatureShow");//使用性质
                        driveUseAttribute = GetJV(vehiclejson, "driveUseAttribute");//行驶证使用性质
                        licenseColorCode = GetJV(vehiclejson, "licenseColorCode");//号牌颜色
                        enrollDate = GetJV(vehiclejson, "enrollDate");//购置日期
                        completeKerbMass = GetJV(vehiclejson, "completeKerbMass");//整备质量
                        vehicleCategory = GetJV(vehiclejson, "vehicleCategory");//交管车辆类型
                        energyType = GetJV(vehiclejson, "energyType");//能源种类
                        suitClause = GetJV(vehiclejson, "suitClause");//适用条款
                    }


                    log.debug("销售信息sales")
                    //销售信息sales
                    String sales = GetJV(bodyjson, "sales");
                    String companyCode=null;
                    String companyName=null;
                    if (!KHUtil.isNull(sales)){
                        JSONObject salesjson = JSONObject.fromObject(sales);
                        companyCode = GetJV(salesjson, "companyCode");//出单机构代码
                        companyName = GetJV(salesjson, "companyName");//出单机构名称
                    }

                    log.debug("险种信息")
                    //险种信息

                    Class<?> riskisArr = jsonObject.getJSONObject("response").getJSONObject("body").get("risk").getClass();


                    //插入表前,先把旧数据删掉
                    String riskdelsql = '''DELETE FROM  PRE_QUOTATION_RISK WHERE ORDERNO=? ''';

                    jt.update(riskdelsql, ORDERNO);
                    if (riskisArr.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr = bodyjson.getJSONArray("risk");

                        for (int i = 0; i < batcharr.size(); i++) {
                            JSONObject dataJson = batcharr.getJSONObject(i);
                            String sumPriceTaxTotal = GetJV(dataJson, "sumPriceTaxTotal");//价税合计
                            String riskCode = GetJV(dataJson, "riskCode");//险种代码
                            String startDate = GetJV(dataJson, "startDate");//起保时间
                            String endDate = GetJV(dataJson, "endDate");//终保时间
                            String effectFlag = GetJV(dataJson, "effectFlag");//即时生效标识
                            String immEffectStartDate = GetJV(dataJson, "immEffectStartDate");//即时生效时间
                            String queryPastDate = GetJV(dataJson, "queryPastDate");//查询码有效期
                            String sumUWPremium = GetJV(dataJson, "sumUWPremium");//总承保保费
                            String lastClaimTimes = GetJV(dataJson, "lastClaimTimes");//上年索赔次数
                            String lastClaimAmount = GetJV(dataJson, "lastClaimAmount");//上年索赔金额
                            String corevalue = GetJV(dataJson, "corevalue");//车辆评分值

                            String insertsql='''
                                Insert into PRE_QUOTATION_RISK  
                              (
                              SYSID,
                              ORDERNO,
                              SUMPRICETAXTOTAL,
                              RISKCODE,
                              STARTDATE,
                              ENDDATE,
                              EFFECTFLAG,
                              IMMEFFECTSTARTDATE,
                              QUERYPASTDATE,
                              SUMUWPREMIUM,
                              LASTCLAIMTIMES,
                              LASTCLAIMAMOUNT,
                              COREVALUE,
                              CREATEDDATE
                              )values
                              (
                              sysguid,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              sysdate
                              )


                                      '''

                            jt.update(insertsql,ORDERNO,sumPriceTaxTotal,riskCode,startDate,endDate,effectFlag,immEffectStartDate,queryPastDate,sumUWPremium,lastClaimTimes,lastClaimAmount,corevalue);
                        }



                    }else if (riskisArr.getName().equals("net.sf.json.JSONObject")){
                        String riskBSbody = GetJV(bodyjson, "risk");
                        if (!KHUtil.isNull(riskBSbody)){
                            JSONObject riskjson = JSONObject.fromObject(riskBSbody);
                            String sumPriceTaxTotal = GetJV(riskjson, "sumPriceTaxTotal");//价税合计
                            String riskCode = GetJV(riskjson, "riskCode");//险种代码
                            String startDate = GetJV(riskjson, "startDate");//起保时间
                            String endDate = GetJV(riskjson, "endDate");//终保时间
                            String effectFlag = GetJV(riskjson, "effectFlag");//即时生效标识
                            String immEffectStartDate = GetJV(riskjson, "immEffectStartDate");//即时生效时间
                            String queryPastDate = GetJV(riskjson, "queryPastDate");//查询码有效期
                            String sumUWPremium = GetJV(riskjson, "sumUWPremium");//总承保保费
                            String lastClaimTimes = GetJV(riskjson, "lastClaimTimes");//上年索赔次数
                            String lastClaimAmount = GetJV(riskjson, "lastClaimAmount");//上年索赔金额
                            String corevalue = GetJV(riskjson, "corevalue");//车辆评分值

                            String insertsql='''
                                Insert into PRE_QUOTATION_RISK  
                              (
                              SYSID,
                              ORDERNO,
                              SUMPRICETAXTOTAL,
                              RISKCODE,
                              STARTDATE,
                              ENDDATE,
                              EFFECTFLAG,
                              IMMEFFECTSTARTDATE,
                              QUERYPASTDATE,
                              SUMUWPREMIUM,
                              LASTCLAIMTIMES,
                              LASTCLAIMAMOUNT,
                              COREVALUE,
                              CREATEDDATE
                              )values
                              (
                              sysguid,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              sysdate
                              )


                                      '''

                            jt.update(insertsql,ORDERNO,sumPriceTaxTotal,riskCode,startDate,endDate,effectFlag,immEffectStartDate,queryPastDate,sumUWPremium,lastClaimTimes,lastClaimAmount,corevalue);

                        }
                    }
                    log.debug("公共信息")
                    //公共信息
                    String commonParam = GetJV(bodyjson, "commonParam");

                    String claimTimes = null;
                    String insureYears = null;
                    String claimAdJustLevel = null;
                    String damagedTimes = null;
                    if (!KHUtil.isNull(commonParam)) {
                        JSONObject commonParamjson = JSONObject.fromObject(commonParam);
                        claimTimes = GetJV(commonParamjson, "claimTimes");//连续出险次数
                        insureYears = GetJV(commonParamjson, "insureYears");//连续承保年数
                        claimAdJustLevel = GetJV(commonParamjson, "claimAdJustLevel");//无赔优级别
                        damagedTimes = GetJV(commonParamjson, "damagedTimes");//往年索赔记录
                    }
                    //商业险ncd系数

                    //插入表前,先把旧数据删掉
                    String delsql = '''DELETE FROM  PRE_QUOTATION_NCDBS WHERE ORDERNO=? ''';
                    jt.update(delsql, ORDERNO);
                    Class<?> isArr = jsonObject.getJSONObject("response").getJSONObject("body").get("ncdBS").getClass();
                    if (isArr.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr = bodyjson.getJSONArray("ncdBS");
                        for (int i = 0; i < batcharr.size(); i++) {
                            JSONObject dataJson = batcharr.getJSONObject(i);
                            String factorCode = GetJV(dataJson, "factorCode");
                            String ciadjustreason = GetJV(dataJson, "ciadjustreason");
                            String NOADJUSTREASON = GetJV(dataJson, "noAdjustReason");
                            String coefficient = GetJV(dataJson, "coefficient");
                            String adjustValue = GetJV(dataJson, "adjustValue");
                            String insertsql = ''' 
                                 Insert into PRE_QUOTATION_NCDBS
                                 (
                                 sysid,
                                 ORDERNO,
                                 FACTORCODE,
                                 CIADJUSTREASON,
                                 NOADJUSTREASON,
                                 COEFFICIENT,
                                 CREATEDDATE,
                                 adjustValue
                                 )values(
                                 sysguid,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 sysdate,
                                 ?                              
                                 )
                                 '''
                            jt.update(insertsql, ORDERNO, factorCode, ciadjustreason, NOADJUSTREASON, coefficient, adjustValue);


                        }
                    } else if (isArr.getName().equals("net.sf.json.JSONObject")) {
                        String ncdBSbody = GetJV(bodyjson, "ncdBS")


                        if (!KHUtil.isNull(ncdBSbody)){
                            JSONObject batcharr = JSONObject.fromObject(ncdBSbody);
                            String factorCode = GetJV(batcharr, "factorCode");
                            String ciadjustreason = GetJV(batcharr, "ciadjustreason");
                            String NOADJUSTREASON = GetJV(batcharr, "noAdjustReason");
                            String coefficient = GetJV(batcharr, "coefficient");
                            String adjustValue = GetJV(batcharr, "adjustValue");
                            String insertsql = ''' 
                                 Insert into PRE_QUOTATION_NCDBS
                                 (
                                 sysid,
                                 ORDERNO,
                                 FACTORCODE,
                                 CIADJUSTREASON,
                                 NOADJUSTREASON,
                                 COEFFICIENT,
                                 CREATEDDATE,
                                 adjustValue
                                 )values(
                                 sysguid,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 sysdate,
                                 ?                             
                                 )

                                 '''

                            jt.update(insertsql, ORDERNO, factorCode, ciadjustreason, NOADJUSTREASON, coefficient, adjustValue);
                        }



                    }

                    //商业险险别信息
                    //插入表前,先把旧数据删掉
                    String delsql2 = '''DELETE FROM  PRE_QUOTATION_RISKITEMINFO WHERE ORDERNO=? ''';
                    jt.update(delsql2, ORDERNO);

                    Class<?> itemKindBSarr = jsonObject.getJSONObject("response").getJSONObject("body").get("itemKindBS").getClass();
                    if (itemKindBSarr.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("itemKindBS");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String kindCode = batcharr2.get(b).get("kindCode");//险别代码
                            String kindName = batcharr2.get(b).get("kindName");//险别名称
                            String relatedInd = batcharr2.get(b).get("relatedInd");//是否投保不计免赔
                            String quantity = batcharr2.get(b).get("quantity");//数量
                            String discount = batcharr2.get(b).get("discount");//折扣率
                            String priceTaxTotal = batcharr2.get(b).get("priceTaxTotal");//价税合计
                            String sumInsured = batcharr2.get(b).get("sumInsured");//保额
                            String deductibleRate = batcharr2.get(b).get("deductibleRate");//约定损失比例
                            String serviceTimes = batcharr2.get(b).get("serviceTimes");//服务次数
                            String benchmarkPremium = batcharr2.get(b).get("benchmarkPremium");//基准保费
                            String insertsql = ''' 
                                 Insert into PRE_QUOTATION_RISKITEMINFO
                                 (
                                 sysid,
                                 ORDERNO,
                                 SY_KINDCODE,
                                 SY_KINDNAME,
                                 SY_SUMINSURED,
                                 SY_PRICETAXTOTAL,
                                 SY_DEDUCTIBLERATE,
                                 SY_SERVICETIMES,
                                 SY_QUANTITY,
                                 relatedInd,
                                 quantity,
                                 discount,
                                 CREATEDDATE,
                                 benchmarkPremium
                                 )values(
                                 sysguid,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 sysdate,
                                 ?                                 
                                 )
                                 '''

                            jt.update(insertsql, ORDERNO, kindCode, kindName, sumInsured, priceTaxTotal, deductibleRate, serviceTimes, quantity, relatedInd, quantity, discount,benchmarkPremium);

                        }
                    } else if (itemKindBSarr.getName().equals("net.sf.json.JSONObject")) {
                        String itemKindBSbody = GetJV(bodyjson, "itemKindBS");

                        if (!KHUtil.isNull(itemKindBSbody)){
                            JSONObject batcharr = JSONObject.fromObject(itemKindBSbody);
                            String kindCode = GetJV(batcharr, "kindCode");//险别代码
                            String kindName = GetJV(batcharr, "kindName");//险别名称
                            String relatedInd = GetJV(batcharr, "relatedInd");//是否投保不计免赔
                            String quantity = GetJV(batcharr, "quantity");//数量
                            String discount = GetJV(batcharr, "discount");//折扣率
                            String priceTaxTotal = GetJV(batcharr, "priceTaxTotal");//价税合计
                            String sumInsured = GetJV(batcharr, "sumInsured");//保额
                            String deductibleRate = GetJV(batcharr, "deductibleRate");//约定损失比例
                            String serviceTimes = GetJV(batcharr, "serviceTimes");//服务次数
                            String benchmarkPremium = GetJV(batcharr, "benchmarkPremium");//基准保费
                            String insertsql = ''' 
                                 Insert into PRE_QUOTATION_RISKITEMINFO
                                 (
                                 sysid,
                                 ORDERNO,
                                 SY_KINDCODE,
                                 SY_KINDNAME,
                                 SY_SUMINSURED,
                                 SY_PRICETAXTOTAL,
                                 SY_DEDUCTIBLERATE,
                                 SY_SERVICETIMES,
                                 SY_QUANTITY,
                                 relatedInd,
                                 quantity,
                                 discount,
                                 CREATEDDATE,
                                 benchmarkPremium
                                 )values(
                                 sysguid,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 sysdate,
                                 ?                                 
                                 )
                                 '''

                            jt.update(insertsql, ORDERNO, kindCode, kindName, sumInsured, priceTaxTotal, deductibleRate, serviceTimes, quantity, relatedInd, quantity, discount,benchmarkPremium);


                        }

                    }

                    //插入表前,先把车辆表旧数据删掉
                    String cardelsql = '''DELETE FROM  PRE_QUOTATION_VEHICLEINFO WHERE ORDERNO=? ''';
                    jt.update(cardelsql, ORDERNO);

                    String carinsersql = '''
    INSERT INTO PRE_QUOTATION_VEHICLEINFO
  (ORDERNO,
   BRANDNAME,
   LICENSENO,
   FRAMENO,
   ENGINENO,
   SINGEINDATE,
   CARCHECKSTATUS,
   CHGOWNERFLAG,
   TRANSFERDATE,
   BSCHGOWNERFLAG,
   SEATCOUNT,
   LOANVEHICLEFLAG,
   NEGOTIATEDACTUALVALUE,
   ACTUALVALUE,
   CARKINDCODE,
   PURCHASEPRICE,
   ATTACHNATURE,
   USENATURESHOW,
   CARUSETYPE,
   CERTIFICATEDATE,
   ENROLLDATE,
   COMPLETEKERBMASS,
   VEHICLECATEGORY,
   ENERGYTYPE,
   SUITCLAUSE,
   CREATEDDATE,
      LICENSECOLORCODE,
   CIMODELCODE,
   CIMODELNAME,
   DRIVEUSEATTRIBUTE
   )
VALUES
  (?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   sysdate,?,?,?,?)


                              ''';
                    jt.update(carinsersql,
                            ORDERNO,
                            brandName,
                            licenseNo,
                            frameNo,
                            engineNo,
                            singeinDate,
                            carCheckStatus,
                            chgOwnerFlag,
                            transferDate,
                            bschgOwnerFlag,
                            seatCount,
                            loanVehicleFlag,
                            negotiatedActualValue,
                            actualValue,
                            carKindCode,
                            purchasePrice,
                            attachNature,
                            useNatureShow,
                            carUseType,
                            certificateDate,
                            enrollDate,
                            completeKerbMass,
                            vehicleCategory,
                            energyType,
                            suitClause,licenseColorCode,ciModelCode,ciModelName,driveUseAttribute
                    )


                    //评分信息
                    String delsql3 = ''' DELETE FROM PRE_QUOTATION_ACTUARY WHERE ORDERNO=?''';
                    jt.update(delsql3, ORDERNO);
                    Class<?> isArr2 = jsonObject.getJSONObject("response").getJSONObject("body").get("actuary").getClass();

                    if (isArr2.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("actuary");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String actuaryName = batcharr2.get(b).get("actuaryName");//评分名称
                            String actuaryCode = batcharr2.get(b).get("actuaryCode");//评分Code
                            String actuaryValue = batcharr2.get(b).get("actuaryValue");//评分值


                            String insersql = '''
                                    Insert into PRE_QUOTATION_ACTUARY
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    ACTUARYNAME,
                                    ACTUARYCODE,
                                    ACTUARYVALUE,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    sysdate
                                    )
                                         ''';

                            jt.update(insersql, ORDERNO, customer_guid, actuaryName, actuaryCode, actualValue);

                        }


                    } else if (isArr2.getName().equals("net.sf.json.JSONObject")) {
                        String actuarybody = GetJV(bodyjson, "actuary");

                        if (!KHUtil.isNull(actuarybody)){
                            JSONObject batcharr = JSONObject.fromObject(actuarybody);
                            String actuaryName = GetJV(batcharr, "actuaryName");//评分名称
                            String actuaryCode = GetJV(batcharr, "actuaryCode");//评分Code
                            String actuaryValue = GetJV(batcharr, "actuaryValue");//评分值

                            String insersql = '''
                                    Insert into PRE_QUOTATION_ACTUARY
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    ACTUARYNAME,
                                    ACTUARYCODE,
                                    ACTUARYVALUE,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    sysdate
                                    )
                                         ''';

                            jt.update(insersql, ORDERNO, customer_guid, actuaryName, actuaryCode, actuaryValue);


                        }


                    }

                    //预审核保信息
                    String delsql4 = ''' DELETE FROM PRE_QUOTATION_FLOWUW WHERE ORDERNO=?''';
                    jt.update(delsql4, ORDERNO);
                    Class<?> isArr3 = jsonObject.getJSONObject("response").getJSONObject("body").get("flowUW").getClass();


                    if (isArr3.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("flowUW");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String resultType = batcharr2.get(b).get("resultType");//结果类型
                            String ruleId = batcharr2.get(b).get("ruleId");//规则编号
                            String description = batcharr2.get(b).get("description");//描述


                            String insersql = '''
                                    Insert into PRE_QUOTATION_FLOWUW
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    resultType,
                                    ruleId,
                                    description,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    sysdate
                                    )
                                         ''';

                            jt.update(insersql, ORDERNO, customer_guid, resultType, ruleId, description);


                        }
                    } else if (isArr3.getName().equals("net.sf.json.JSONObject")) {
                        String flowUWbody = GetJV(bodyjson, "flowUW")

                        if (!KHUtil.isNull(flowUWbody)){
                            JSONObject batcharr = JSONObject.fromObject(flowUWbody);
                            String resultType = GetJV(batcharr, "resultType");//结果类型
                            String ruleId = GetJV(batcharr, "ruleId");//规则编号
                            String description = GetJV(batcharr, "description");//描述

                            String insersql = '''
                                    Insert into PRE_QUOTATION_FLOWUW
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    resultType,
                                    ruleId,
                                    description,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    sysdate
                                    )
                                         ''';

                            jt.update(insersql, ORDERNO, customer_guid, resultType, ruleId, description);

                        }




                    }


                    //预审复核信息

                    String delsql5 = ''' DELETE FROM PRE_QUOTATION_flowApprov WHERE ORDERNO=?''';
                    jt.update(delsql5, ORDERNO);
                    Class<?> isArr4 = jsonObject.getJSONObject("response").getJSONObject("body").get("flowApprov").getClass();


                    if (isArr4.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("flowApprov");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String resultType = batcharr2.get(b).get("resultType");//结果类型
                            String ruleId = batcharr2.get(b).get("ruleId");//规则编号
                            String description = batcharr2.get(b).get("description");//描述
                            String insersql = '''
                                    Insert into PRE_QUOTATION_flowApprov
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    resultType,
                                    ruleId,
                                    description,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    sysdate
                                    )
                                         ''';

                            jt.update(insersql, ORDERNO, customer_guid, resultType, ruleId, description);


                        }
                    } else if (isArr4.getName().equals("net.sf.json.JSONObject")) {


                        String flowUWbody = GetJV(bodyjson, "flowUW");

                        if (!KHUtil.isNull(flowUWbody)){
                            JSONObject batcharr = JSONObject.fromObject(flowUWbody);
                            String resultType = GetJV(batcharr, "resultType");//结果类型
                            String ruleId = GetJV(batcharr, "ruleId");//规则编号
                            String description = GetJV(batcharr, "description");//描述

                            String insersql = '''
                                    Insert into PRE_QUOTATION_flowApprov
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    resultType,
                                    ruleId,
                                    description,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    sysdate
                                    )
                                         ''';

                            jt.update(insersql, ORDERNO, customer_guid, resultType, ruleId, description);



                        }



                    }

                    //违法信息
                    String delsql6 = ''' DELETE FROM PRE_QUOTATION_PECCANCYLIST WHERE ORDERNO=?''';
                    jt.update(delsql6, ORDERNO);
                    Class<?> isArr5 = jsonObject.getJSONObject("response").getJSONObject("body").get("peccancyList").getClass();


                    if (isArr5.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("peccancyList");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String peccancyAction = batcharr2.get(b).get("peccancyAction");//违法行为代码
                            String peccancyType = batcharr2.get(b).get("peccancyType");//违法记录类型
                            String peccancyCount = batcharr2.get(b).get("peccancyCount");//违法行为次数
                            String drinkDrivingCount = batcharr2.get(b).get("drinkDrivingCount");//醉酒驾驶次数
                            String peccancyTime = batcharr2.get(b).get("peccancyTime");//违法时间
                            String accEptDate = batcharr2.get(b).get("accEptDate");//违法受理时间
                            String peccancyAddress = batcharr2.get(b).get("peccancyAddress");//违法地点
                            String coeff = batcharr2.get(b).get("coeff");//调整系数
                            String insersql = '''
                                       Insert into PRE_QUOTATION_PECCANCYLIST
                                       (
                                       sysid,
                                       ORDERNO,
                                       PECCANCYACTION,
                                       PECCANCYTYPE,
                                       PECCANCYCOUNT,
                                       DRINKDRIVINGCOUNT,
                                       PECCANCYTIME,
                                       ACCEPTDATE,
                                       PECCANCYADDRESS,
                                       COEFF,
                                       CREATEDDATE,
                                       CUSTOMER_GUID
                                       )
                                       values
                                       (
                                       sysguid,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       sysdate,
                                       ?
                                       )
                                        ''';

                            jt.update(insersql, ORDERNO, peccancyAction, peccancyType, peccancyCount, drinkDrivingCount, peccancyTime, accEptDate, peccancyAddress, coeff);

                        }

                    } else if (isArr5.getName().equals("net.sf.json.JSONObject")) {
                        String peccancyListbody = GetJV(bodyjson, "peccancyList");

                        if (!KHUtil.isNull(peccancyListbody)){
                            JSONObject batcharr = JSONObject.fromObject(peccancyListbody);

                            String peccancyAction = GetJV(batcharr, "peccancyAction");//违法行为代码
                            String peccancyType = GetJV(batcharr, "peccancyType");//违法记录类型
                            String peccancyCount = GetJV(batcharr, "peccancyCount");//违法行为次数
                            String drinkDrivingCount = GetJV(batcharr, "drinkDrivingCount");//醉酒驾驶次数
                            String peccancyTime = GetJV(batcharr, "peccancyTime");//违法时间
                            String accEptDate = GetJV(batcharr, "accEptDate");//违法受理时间
                            String peccancyAddress = GetJV(batcharr, "peccancyAddress");//违法地点
                            String coeff = GetJV(batcharr, "coeff");//调整系数

                            String insersql = '''
                                       Insert into PRE_QUOTATION_PECCANCYLIST
                                       (
                                       sysid,
                                       ORDERNO,
                                       PECCANCYACTION,
                                       PECCANCYTYPE,
                                       PECCANCYCOUNT,
                                       DRINKDRIVINGCOUNT,
                                       PECCANCYTIME,
                                       ACCEPTDATE,
                                       PECCANCYADDRESS,
                                       COEFF,
                                       CREATEDDATE,
                                       CUSTOMER_GUID
                                       )
                                       values
                                       (
                                       sysguid,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       sysdate,
                                       ?
                                       )
                                        ''';

                            jt.update(insersql, ORDERNO, peccancyAction, peccancyType, peccancyCount, drinkDrivingCount, peccancyTime, accEptDate, peccancyAddress, coeff);


                        }


                    }

                    //费率因子节点
                    String delsql7 = ''' DELETE FROM PRE_QUOTATION_riskProfit WHERE ORDERNO=?''';
                    jt.update(delsql7, ORDERNO);
                    Class<?> isArr6 = jsonObject.getJSONObject("response").getJSONObject("body").get("riskProfit").getClass();

                    if (isArr6.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("riskProfit");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String profitCode = batcharr2.get(b).get("profitCode");//费率因子代码
                            String profitName = batcharr2.get(b).get("profitName");//违法记录类型
                            String rate = batcharr2.get(b).get("rate");//费率系数值

                            String insertsql = ''' 
                                       Insert into 
                                       PRE_QUOTATION_riskProfit (
                                         sysid,
                                       ORDERNO,
                                       PROFITCODE,
                                       profitName,
                                       rate,
                                       customer_guid,
                                       CREATEDDATE
                                       )values(
                                       sysguid,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       sysdate
                                       )
                                              '''
                            jt.update(insertsql, ORDERNO, profitCode, profitName, rate, customer_guid);


                        }
                    } else if (isArr6.getName().equals("net.sf.json.JSONObject")) {
                        String peccancyListbody = GetJV(bodyjson, "riskProfit")

                        if (!KHUtil.isNull(peccancyListbody)){
                            JSONObject batcharr = JSONObject.fromObject(peccancyListbody);
                            String profitCode = GetJV(batcharr, "profitCode");//费率因子代码
                            String profitName = GetJV(batcharr, "profitName");//违法记录类型
                            String rate = GetJV(batcharr, "rate");//费率系数值

                            String insertsql = ''' 
                                       Insert into 
                                       PRE_QUOTATION_riskProfit (
                                         sysid,
                                       ORDERNO,
                                       PROFITCODE,
                                       profitName,
                                       rate,
                                       customer_guid,
                                       CREATEDDATE
                                       )values(
                                       sysguid,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       sysdate
                                       )
                                              '''
                            jt.update(insertsql, ORDERNO, profitCode, profitName, rate, customer_guid);

                        }




                    }


                    //评分主信息
                    //查询评分表里是否存在
                    String delsqlzb = ''' 
                               DELETE   from  pre_quotation_maininfo WHERE ORDERNO=?
                                  ''';

                    jt.update(delsqlzb,ORDERNO);

                    //插入预评分主表
                    String insertsql = ''' 
                          INSERT INTO pre_quotation_maininfo
          (ORDERNO,
           REGISTERNO,
           LOSSTIME,
           ENDCASETIME,
           CLAIMNOTIFICATIONNO,
           ACCIDENTDEATHFLAG,
           LOSSFEE,
           CLAIMTIMES,
           INSUREYEARS,
           CLAIMADJUSTLEVEL,
           DAMAGEDTIMES,
           CUSTOMERNAME,
           IDENTIFYNUMBER,
           BIRTHDATE,
           SEX,
           OWNERNATURE,
           IDENTIFYTYPE,
           LINKEDFLAG,
           DISCOUNTUP,
           DISCOUNTDOWN,
           TPFLAG,
           XZXID,
           PREMIUMTRIALFLAG,
           COMPANYCODE,
           COMPANYNAME,
           policyNo,
           demandNo,
           CREATEDDATE,customer_guid,CONFIG_ID)
        VALUES
          (
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,       
           sysdate,?,?)    
                      ''';



                    jt.update(insertsql,
                            ORDERNO,
                            registerNo,
                            lossTime,
                            endCaseTime,
                            claimNotificationNo,
                            accidentDeathFlag,
                            lossFee,
                            claimTimes,
                            insureYears,
                            claimAdJustLevel,
                            damagedTimes,
                            name,
                            identifyNumber,
                            birthDate,
                            sex,
                            ownerNature,
                            identifyType,
                            linkedFlag,
                            discountUp,
                            discountDown,
                            tpFlag,
                            xzxId,
                            premiumTrialFlag,
                            companyCode,
                            companyName,
                            policyNo,
                            demandNo,
                            customer_guid,SYSID
                    );





                    //把推送表数据改成成功
                    String updatesql = ''' 
                   Update push_h5_customer 
                    set
                   flag='1',
                   MODIFIEDDATE=sysdate,
                   MODIFIEDGROUP='SYSTEM',
                   MODIFIEDBY='SELITE',
                   REQUESTINFO=?,
                   REQUESTDATE=sysdate,
                   RESPONSEINFO=?,
                   RESPONSEDATE=sysdate,
                   ERRMSG='',
                   loserattemptnum=0
                   where CUSTOMER_GUID=?
                      ''';
                    jt.update(updatesql, defrequstInfo.toString(), postCallBackBody.toString(), customer_guid);

                    //插入轨迹表
                    String USH_H5_CUSTOMER_HISTORY = '''
                    insert into PUSH_H5_CUSTOMER_HISTORY
                    (
                    sysid,
                    CUSTOMER_GUID,
                    CUSLISTNAME,
                    CREATEDGROUP,
                    CREATEDBY,
                    CREATEDDATE,
                    ISFLAG,
                    REQUESTINFO,
                    REQUESTDATE,
                    RESPONSEINFO,
                    RESPONSEDATE,
                    ROLEGROUP_ID,
                     REAMRK,
                     ERRMSG
                    )
                    select 
                    sysguid,
                    CUSTOMER_GUID,
                    CUSLISTNAME,
                    CREATEDGROUP,
                    CREATEDBY,
                    sysdate,
                    ISFLAG,
                    REQUESTINFO,
                    REQUESTDATE,
                    RESPONSEINFO,
                    RESPONSEDATE,
                    ROLEGROUP_ID,
                    '推送成功',
                    ERRMSG
                    from PUSH_H5_CUSTOMER pu5
                    where  pu5.customer_guid=?
                   

                    '''

                    jt.update(USH_H5_CUSTOMER_HISTORY, customer_guid);

                } else {
                    log.debug("【预评分】推送H5  V03返回标识失败,该推送名单标识为失败！");
                    updatestate(eliteBean, customer_guid, defrequstInfo.toString(), postCallBackBody.toString(),errMsg);
                }


            } else {
                //城市信息找不到失败
                updatestate(eliteBean, customer_guid, "城市信息找不到", "城市信息找不到", "城市信息找不到");
            }


        } catch (Exception e) {
            log.error("【预评分】V03接口推送H5异常：" + e.getMessage());

            updatestateXL(eliteBean, customer_guid, defrequstInfo.toString(), e.getMessage(),e.getMessage());
        }

        return status.toString();
    }


    /**
     * 续保名单调用接口
     * @param eliteBean
     * @param frame_code
     * @param customer_guid
     * @param SERVICE_AREA
     * @param city_id
     * @return
     */
    public static String push_h5_xbPremiumCalculate(EliteBean eliteBean, String frame_code, String customer_guid, String SERVICE_AREA, String city_id, String CUSTOMERNAME) {
        log.debug("【预评分续保名单】xbPremiumCalculate开始执行");
        String status = null;//状态标识
        String defrequstInfo=null;
        try {

            Date date = new Date();
            //消息ID
            String msgId = KHUtil.getRandomString(36);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            String datetime = dateFormat.format(new Date());
            String get36 = KHUtil.getRandomString(36);
            String clientName = KHDBConfig.getParam(eliteBean, "H5_SHH", "");//商户话哦
            String privateKey = KHDBConfig.getParam(eliteBean, "H5_KEY", "");//私钥
            String api = "xbPremiumCalculate";
            JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());
            String sql = "select WEBSERVICEURL From sysc_interface where WEBTYPE='H5_URL'";
            List<Map<String, Object>> createlist = jt.queryForList(sql);
            String geturl = createlist.get(0).get("WEBSERVICEURL");
            String path = geturl + "/ecms2/portal";//地址

            String cityCode = null;//城市代码
            String applyNo = null;//决策单元
            String PROVINCE_ID = null;//省份ID
            String PROVINCE_DESC = null;//省份名称
            String THRIN_RISK = null;//三者险
            String DRIVER_RISK = null;//司机险
            String PASSENGER_RISK = null;//乘客险
            String configcustomerid=null;
            //查找城市代码
            List chaxuncityList = eliteBean.chaxun_sql(" selecT CITY_ID,PROVINCE_ID from C_CITY where  RegEXP_LIKE(CITY_DESC,'" + city_id + "')  and rownum<=1", "dataSource");
            if (chaxuncityList.size() > 0) {
                cityCode = chaxuncityList.get(0).get("CITY_ID");  //城市
                PROVINCE_ID = chaxuncityList.get(0).get("PROVINCE_ID");  //省份ID


                //查找省份代码
                List chaxunPROVINCEList = eliteBean.chaxun_sql(" selecT PROVINCE_DESC from C_PROVINCE where PROVINCE_ID = '" + PROVINCE_ID + "' and rownum<=1", "dataSource");

                if (chaxunPROVINCEList.size() > 0) {
                    PROVINCE_DESC = chaxunPROVINCEList.get(0).get("PROVINCE_DESC")
                    //查询预评分销售信息配置表
                    List ypfsalaList = eliteBean.chaxun_sql(" selecT THRIN_RISK,DRIVER_RISK,PASSENGER_RISK,DECISION,CUSTOMERID from push_h5_sale_config where RegEXP_LIKE(TWO_ORGANIZATION,'" + PROVINCE_DESC + "') and  RegEXP_LIKE(THREE_ORGANIZATION,'" + city_id + "')  and rownum<=1", "dataSource");
                    if (ypfsalaList.size() > 0) {
                        THRIN_RISK = ypfsalaList.get(0).get("THRIN_RISK");//三者险
                        DRIVER_RISK = ypfsalaList.get(0).get("DRIVER_RISK");//司机险
                        PASSENGER_RISK = ypfsalaList.get(0).get("PASSENGER_RISK");//乘客险
                        applyNo = ypfsalaList.get(0).get("DECISION");//决策单元
                        configcustomerid= ypfsalaList.get(0).get("CUSTOMERID");//身份证号
                    } else {
                        //没匹配到用其他兜底销售信息
                        List qtypfsalaList = eliteBean.chaxun_sql(" selecT THRIN_RISK,DRIVER_RISK,PASSENGER_RISK,DECISION,CUSTOMERID from push_h5_sale_config where TWO_ORGANIZATION='其他' and rownum<=1", "dataSource");
                        if (qtypfsalaList.size() > 0) {
                            THRIN_RISK = qtypfsalaList.get(0).get("THRIN_RISK");//三者险
                            DRIVER_RISK = qtypfsalaList.get(0).get("DRIVER_RISK");//司机险
                            PASSENGER_RISK = qtypfsalaList.get(0).get("PASSENGER_RISK");//乘客险
                            applyNo = qtypfsalaList.get(0).get("DECISION");//决策单元
                            configcustomerid= qtypfsalaList.get(0).get("CUSTOMERID");//身份证号


                        }
                    }
                }




                defrequstInfo = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
             <request>
             <head>
             <msgId>$msgId</msgId>
             <timeStamp>$datetime</timeStamp>
             <userCode>$customer_guid</userCode>
             <clientName>$clientName</clientName>
             </head>
             <body>
             <sales>
             <cityCode>$cityCode</cityCode>
             <solutionCode></solutionCode>
             <applyNo>$applyNo</applyNo>
             <cooperateSiteCode>$SERVICE_AREA</cooperateSiteCode>
             <groupNo></groupNo>
             <salesmanCode></salesmanCode>
             </sales>
             <vehicle>
             <frameNo>$frame_code</frameNo>
             </vehicle>
             <carOwner>
             <name>$CUSTOMERNAME</name>
             </carOwner>
             </body>
             </request>
             """;


                /**
                 String defrequstInfo = """<?xml version="1.0" encoding="UTF-8"?>

                 <request>
                 <head>
                 <msgId>$msgId</msgId>
                 <timeStamp>$datetime</timeStamp>
                 <userCode>$customer_guid</userCode>
                 <clientName>S179004</clientName>
                 </head>
                 <body>
                 <sales>
                 <cityCode>430400</cityCode>
                 <solutionCode/>
                 <applyNo>3100000001</applyNo>
                 <cooperateSiteCode>0601010102</cooperateSiteCode>
                 <groupNo/>
                 <salesmanCode/>
                 </sales>
                 <vehicle>
                 <frameNo>LSCABN3E8KE676856</frameNo>
                 </vehicle>
                 <carOwner>
                 <name>倪云菊</name>
                 </carOwner>

                 </body>
                 </request>""";
                 **/

                log.debug("【预评分】推送H5 xbPremiumCalculate请求报文:" + defrequstInfo);


                log.debug("【预评分】推送H5 xbPremiumCalculate请求报文:" + defrequstInfo);
                //对报文进行加签
                byte[] signBytes;
                String respEncode = Base64.encode(defrequstInfo.getBytes(defaultCharset));
                signBytes = sign(respEncode.replace("\n", "").getBytes(), Base64.decode(privateKey), algorithm);
                String respSign = Base64.encode(signBytes, Integer.MAX_VALUE);
                //越过SSL验证
                SSLContext ctx = SSLContext.getInstance("TLS");
                SSLContext.setDefault(ctx);


                log.debug("【预评分】推送H5 xbPremiumCalculate请求地址:" + path.toString() + "/" + clientName.toString() + "/" + api.toString());

                //设置请求表头
                Map<String, String> TokenParams = new HashMap<String, String>();
                TokenParams.put("TP-SIGN", respSign);

                //调用请求H5
                String postCallBackBody = Util.doHttpPostUseHead(String.format("%s/%s/%s", path, clientName, api), defrequstInfo.toString(), "UTF-8", 50000, 0, TokenParams, "");
                //模拟H5返回
                //  def postCallBackBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><head><msgId>c1480f3d-3580-4293-a0dd-8ef10653ab39</msgId><timeStamp>2017-12-18 10:18:46</timeStamp><session>b1870ca0-deac-4913-8e08-6e0b6f98af44</session><userCode>oeRlIuCu9HU4K-qIrVKahdof8XgQ</userCode><clientName>H007001</clientName><status>S</status></head><body><order><orderNo>f80c10f1-587c-403f-ab21-96df60ccc069</orderNo></order></body></response>"
                log.debug("【预评分】推送H5 xbPremiumCalculate返回报文:" + postCallBackBody);
                //转换成json
                String json = XML.toJSONObject(postCallBackBody);

                JSONObject jsonObject = JSONObject.fromObject(json);

                log.debug("【预评分】推送H5 xbPremiumCalculateXML转换后返回的JSON报文：" + jsonObject.toString());



                log.debug("【预评分】推送H5 V03 XML转换后返回的JSON报文：" + jsonObject.toString());


                String responseJson = GetJV(jsonObject, "response");

                JSONObject headjson = JSONObject.fromObject(responseJson);


                String headstrjson = GetJV(headjson, "head");

                JSONObject headjson2 = JSONObject.fromObject(headstrjson);


                status = GetJV(headjson2, "status");//返回报文标识    S/成功 F/失败
                String errCode = GetJV(headjson2, "errCode");//返回报文失败编码
                String errMsg = GetJV(headjson2, "errMsg");//返回报文失败消息


                if (status.equals("S")){
                    String body = GetJV(headjson, "body");
                    JSONObject bodyjson = JSONObject.fromObject(body);

                    //获取订单号
                    String order = GetJV(bodyjson, "order");

                    JSONObject orderjson = JSONObject.fromObject(order);

                    String ORDERNO=GetJV(orderjson,"orderNo");

                    log.debug("扩展信息")
                    //扩展信息

                    String linkedFlag = Get
                    String premiumTrialFlag = null;
                    String tpFlag = null;
                    String xzxId = null;
                    String discountDown = null;
                    String discountUp = null;
                    String ncd = null;
                    String extend = GetJV(bodyjson, "extend");
                    if (!KHUtil.isNull(extend)) {
                        JSONObject extendjson = JSONObject.fromObject(extend);
                        linkedFlag = GetJV(extendjson, "linkedFlag");//能否价费联动
                        premiumTrialFlag = GetJV(extendjson, "premiumTrialFlag");//保费试算标识
                        tpFlag = GetJV(extendjson, "tpFlag");//能否进行特批标识
                        xzxId = GetJV(extendjson, "xzxId");//新转续标识
                        discountDown = GetJV(extendjson, "discountDown");//折扣下限
                        discountUp = GetJV(extendjson, "discountUp");//折扣上限
                        ncd = GetJV(extendjson, "ncd");//?
                    }
                    log.debug("车主信息")
                    //车主信息
                    String carOwner = GetJV(bodyjson, "carOwner");
                    JSONObject carOwnerjson = JSONObject.fromObject(carOwner);
                    String name = GetJV(carOwnerjson, "name");//车主名称
                    String identifyNumber = GetJV(carOwnerjson, "identifyNumber");//证件号
                    String ownerNature = GetJV(carOwnerjson, "ownerNature");//车主性质
                    String identifyType = GetJV(carOwnerjson, "identifyType");//车主证件类型
                    String birthDate = GetJV(carOwnerjson, "birthDate");//生日
                    String sex = GetJV(carOwnerjson, "sex");//性别


                    String demandNo = null;
                    String registerNo = null;
                    String lossTime = null;
                    String endCaseTime = null;
                    String lossFee = null;
                    String claimNotificationNo = null;
                    String accidentDeathFlag = null;
                    String policyNo = null;

                    log.debug("出险理赔信息");
                    //出险理赔信息
                    String demandPay = GetJV(bodyjson, "demandPay");
                    if (!KHUtil.isNull(demandPay)) {
                        JSONObject demandPayjson = JSONObject.fromObject(demandPay);
                        demandNo = GetJV(demandPayjson, "demandNo");//查询码
                        registerNo = GetJV(demandPayjson, "registerNo");//立案号
                        lossTime = GetJV(demandPayjson, "lossTime");//出险时间
                        endCaseTime = GetJV(demandPayjson, "endCaseTime");//结案时间
                        lossFee = GetJV(demandPayjson, "lossFee");//赔付金额
                        claimNotificationNo = GetJV(demandPayjson, "claimNotificationNo");//理赔编码
                        accidentDeathFlag = GetJV(demandPayjson, "accidentDeathFlag");//是否发生有责任交通死亡事
                        policyNo = GetJV(demandPayjson, "policyNo");//保单号

                    }

                    log.debug("车辆信息")
                    //车辆信息
                    String vehicle = GetJV(bodyjson, "vehicle");
                    JSONObject vehiclejson = JSONObject.fromObject(vehicle);
                    String carCheckStatus = GetJV(vehiclejson, "carCheckStatus");//验车情况
                    String brandName = GetJV(vehiclejson, "brandName");//品牌型号
                    String licenseNo = GetJV(vehiclejson, "licenseNo");//车牌号
                    String frameNo = GetJV(vehiclejson, "frameNo");//车架号
                    String engineNo = GetJV(vehiclejson, "engineNo");//发动机号
                    String chgOwnerFlag = GetJV(vehiclejson, "chgOwnerFlag");//是否过户车
                    String transferDate = GetJV(vehiclejson, "transferDate");//过户日期
                    String bschgOwnerFlag = GetJV(vehiclejson, "bschgOwnerFlag");//商业过户车标识
                    String bzchgOwnerFlag = GetJV(vehiclejson, "bzchgOwnerFlag");//交强过户车标识
                    String singeinDate = GetJV(vehiclejson, "singeinDate");//登记日期
                    String certificateDate = GetJV(vehiclejson, "certificateDate");//发证日期
                    String seatCount = GetJV(vehiclejson, "seatCount");//座位数
                    String loanVehicleFlag = GetJV(vehiclejson, "loanVehicleFlag");//是否贷款车
                    String negotiatedActualValue = GetJV(vehiclejson, "negotiatedActualValue");//协商实际价值
                    String actualValue = GetJV(vehiclejson, "actualValue");//实际价值
                    String carKindCode = GetJV(vehiclejson, "carKindCode");//车辆种类
                    String purchasePrice = GetJV(vehiclejson, "purchasePrice");//新车购置价
                    String ciModelCode = GetJV(vehiclejson, "ciModelCode");//行业车型编码
                    String ciModelName = GetJV(vehiclejson, "ciModelName");//行业车型名称
                    String carUseType = GetJV(vehiclejson, "carUseType");//车辆用途
                    String attachNature = GetJV(vehiclejson, "attachNature");//所属性质
                    String useNatureShow = GetJV(vehiclejson, "useNatureShow");//使用性质
                    String driveUseAttribute = GetJV(vehiclejson, "driveUseAttribute");//行驶证使用性质
                    String licenseColorCode = GetJV(vehiclejson, "licenseColorCode");//号牌颜色
                    String enrollDate = GetJV(vehiclejson, "enrollDate");//购置日期
                    String completeKerbMass = GetJV(vehiclejson, "completeKerbMass");//整备质量
                    String vehicleCategory = GetJV(vehiclejson, "vehicleCategory");//交管车辆类型
                    String energyType = GetJV(vehiclejson, "energyType");//能源种类
                    String suitClause = GetJV(vehiclejson, "suitClause");//适用条款
                    String distinguishVanAreaCode = GetJV(vehiclejson, "distinguishVanAreaCode");//小货车分区
                    String commercialCarGrade = GetJV(vehiclejson, "commercialCarGrade");//商用车评级
                    String zjxlGrade = GetJV(vehiclejson, "zjxlGrade");//中交兴路评分

                    //精准车型信息（vehicleDepSD
                    Class<?> vehicleDepSDisArr = jsonObject.getJSONObject("response").getJSONObject("body").get("vehicleDepSD").getClass();

                    if (vehicleDepSDisArr.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr = bodyjson.getJSONArray("vehicleDepSD");
                        for (int i = 0; i < batcharr.size(); i++) {
                            JSONObject dataJson = batcharr.getJSONObject(i);
                            String modelCode = GetJV(dataJson, "modelCode");
                            String noticeType = GetJV(dataJson, "noticeType");
                            String warning = GetJV(dataJson, "warning");
                            String brand = GetJV(dataJson, "brand");
                            String tradeName = GetJV(dataJson, "tradeName");
                            String carName = GetJV(dataJson, "carName");
                            String series = GetJV(dataJson, "series");
                            String modelFlag = GetJV(dataJson, "modelFlag");

                            String insertsql=''' 
                                 iNSERT INTO PRE_QUOTATION_VEHICLEDEPSD
                                 (
                                 SYSID,
                                 ORDERNO,
                                 modelCode,
                                 noticeType,
                                 warning,
                                 brand,
                                 tradeName,
                                 carName,
                                 series,
                                 modelFlag,
                                 CREATEDDATE
                                 )values(
                                 sysguid,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 sysdate
                                 )
                                 
                                 ''';

                            jt.update(insertsql,ORDERNO,modelCode,noticeType,warning,brand,tradeName,carName,series,modelFlag);


                        }


                    } else if (vehicleDepSDisArr.getName().equals("net.sf.json.JSONObject")) {
                        String ncdBSbody = GetJV(bodyjson, "vehicleDepSD")
                        JSONObject batcharr = JSONObject.fromObject(ncdBSbody);

                        String modelCode = GetJV(batcharr, "modelCode");
                        String noticeType = GetJV(batcharr, "noticeType");
                        String warning = GetJV(batcharr, "warning");
                        String brand = GetJV(batcharr, "brand");
                        String tradeName = GetJV(batcharr, "tradeName");
                        String carName = GetJV(batcharr, "carName");
                        String series = GetJV(batcharr, "series");
                        String modelFlag = GetJV(batcharr, "modelFlag");

                        String insertsql=''' 
                                 iNSERT INTO PRE_QUOTATION_VEHICLEDEPSD
                                 (
                                 SYSID,
                                 ORDERNO,
                                 modelCode,
                                 noticeType,
                                 warning,
                                 brand,
                                 tradeName,
                                 carName,
                                 series,
                                 modelFlag,
                                 CREATEDDATE
                                 )values(
                                 sysguid,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 sysdate
                                 )
                                 
                                 ''';

                        jt.update(insertsql,ORDERNO,modelCode,noticeType,warning,brand,tradeName,carName,series,modelFlag);


                    }




                    log.debug("销售信息sales")
                    //销售信息sales
                    String sales = GetJV(bodyjson, "sales");
                    String companyCode=null;
                    String companyName=null;
                    if (!KHUtil.isNull(sales)){
                        JSONObject salesjson = JSONObject.fromObject(sales);
                        companyCode = GetJV(salesjson, "companyCode");//出单机构代码
                        companyName = GetJV(salesjson, "companyName");//出单机构名称
                    }
                    log.debug("险种信息")
                    //险种信息

                    Class<?> riskisArr = jsonObject.getJSONObject("response").getJSONObject("body").get("risk").getClass();


                    //插入表前,先把旧数据删掉
                    String riskdelsql = '''DELETE FROM  PRE_QUOTATION_RISK WHERE ORDERNO=? ''';

                    jt.update(riskdelsql, ORDERNO);
                    if (riskisArr.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr = bodyjson.getJSONArray("risk");
                        for (int i = 0; i < batcharr.size(); i++) {
                            JSONObject dataJson = batcharr.getJSONObject(i);


                            String sumPriceTaxTotal = GetJV(dataJson, "sumPriceTaxTotal");//价税合计
                            String riskCode = GetJV(dataJson, "riskCode");//险种代码
                            String startDate = GetJV(dataJson, "startDate");//起保时间
                            String endDate = GetJV(dataJson, "endDate");//终保时间
                            String effectFlag = GetJV(dataJson, "effectFlag");//即时生效标识
                            String immEffectStartDate = GetJV(dataJson, "immEffectStartDate");//即时生效时间
                            String queryPastDate = GetJV(dataJson, "queryPastDate");//查询码有效期
                            String sumUWPremium = GetJV(dataJson, "sumUWPremium");//总承保保费
                            String lastClaimTimes = GetJV(dataJson, "lastClaimTimes");//上年索赔次数
                            String lastClaimAmount = GetJV(dataJson, "lastClaimAmount");//上年索赔金额
                            String corevalue = GetJV(dataJson, "corevalue");//车辆评分值


                            String insertsql='''
                                Insert into PRE_QUOTATION_RISK  
                              (
                              SYSID,
                              ORDERNO,
                              SUMPRICETAXTOTAL,
                              RISKCODE,
                              STARTDATE,
                              ENDDATE,
                              EFFECTFLAG,
                              IMMEFFECTSTARTDATE,
                              QUERYPASTDATE,
                              SUMUWPREMIUM,
                              LASTCLAIMTIMES,
                              LASTCLAIMAMOUNT,
                              COREVALUE,
                              CREATEDDATE
                              )values
                              (
                              sysguid,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              sysdate
                              )


                                      '''

                            jt.update(insertsql,ORDERNO,sumPriceTaxTotal,riskCode,startDate,endDate,effectFlag,immEffectStartDate,queryPastDate,sumUWPremium,lastClaimTimes,lastClaimAmount,corevalue);

                            if (!KHUtil.isNull(corevalue)){

                                String insersql = '''
                                    Insert into PRE_QUOTATION_ACTUARY
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    ACTUARYNAME,
                                    ACTUARYCODE,
                                    ACTUARYVALUE,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    'TP_Actuary_COREVALUE',
                                    ?,
                                    sysdate
                                    )
                                         ''';

                                jt.update(insersql, ORDERNO, customer_guid, "太平评分-续保"+riskCode, corevalue);


                            }

                        }



                    }else if (riskisArr.getName().equals("net.sf.json.JSONObject")){
                        String riskBSbody = GetJV(bodyjson, "risk")
                        JSONObject riskjson = JSONObject.fromObject(riskBSbody);

                        String sumPriceTaxTotal = GetJV(riskjson, "sumPriceTaxTotal");//价税合计
                        String riskCode = GetJV(riskjson, "riskCode");//险种代码
                        String startDate = GetJV(riskjson, "startDate");//起保时间
                        String endDate = GetJV(riskjson, "endDate");//终保时间
                        String effectFlag = GetJV(riskjson, "effectFlag");//即时生效标识
                        String immEffectStartDate = GetJV(riskjson, "immEffectStartDate");//即时生效时间
                        String queryPastDate = GetJV(riskjson, "queryPastDate");//查询码有效期
                        String sumUWPremium = GetJV(riskjson, "sumUWPremium");//总承保保费
                        String lastClaimTimes = GetJV(riskjson, "lastClaimTimes");//上年索赔次数
                        String lastClaimAmount = GetJV(riskjson, "lastClaimAmount");//上年索赔金额
                        String corevalue = GetJV(riskjson, "corevalue");//车辆评分值


                        String insertsql='''
                                Insert into PRE_QUOTATION_RISK  
                              (
                              SYSID,
                              ORDERNO,
                              SUMPRICETAXTOTAL,
                              RISKCODE,
                              STARTDATE,
                              ENDDATE,
                              EFFECTFLAG,
                              IMMEFFECTSTARTDATE,
                              QUERYPASTDATE,
                              SUMUWPREMIUM,
                              LASTCLAIMTIMES,
                              LASTCLAIMAMOUNT,
                              COREVALUE,
                              CREATEDDATE
                              )values
                              (
                              sysguid,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              ?,
                              sysdate
                              )


                                      '''

                        jt.update(insertsql,ORDERNO,sumPriceTaxTotal,riskCode,startDate,endDate,effectFlag,immEffectStartDate,queryPastDate,sumUWPremium,lastClaimTimes,lastClaimAmount,corevalue);
                        if (!KHUtil.isNull(corevalue)){

                            String insersql = '''
                                    Insert into PRE_QUOTATION_ACTUARY
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    ACTUARYNAME,
                                    ACTUARYCODE,
                                    ACTUARYVALUE,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    'TP_Actuary_COREVALUE',
                                    ?,
                                    sysdate
                                    )
                                         ''';

                            jt.update(insersql, ORDERNO, customer_guid, "太平评分-续保"+riskCode, corevalue);


                        }
                    }
                    log.debug("公共信息")
                    //公共信息
                    String commonParam = GetJV(bodyjson, "commonParam");

                    String claimTimes = null;
                    String insureYears = null;
                    String claimAdJustLevel = null;
                    String damagedTimes = null;
                    if (!KHUtil.isNull(commonParam)) {
                        JSONObject commonParamjson = JSONObject.fromObject(commonParam);
                        claimTimes = GetJV(commonParamjson, "claimTimes");//连续出险次数
                        insureYears = GetJV(commonParamjson, "insureYears");//连续承保年数
                        claimAdJustLevel = GetJV(commonParamjson, "claimAdJustLevel");//无赔优级别
                        damagedTimes = GetJV(commonParamjson, "damagedTimes");//往年索赔记录
                    }
                    //商业险ncd系数

                    //插入表前,先把旧数据删掉
                    String delsql = '''DELETE FROM  PRE_QUOTATION_NCDBS WHERE ORDERNO=? ''';
                    jt.update(delsql, ORDERNO);
                    Class<?> isArr = jsonObject.getJSONObject("response").getJSONObject("body").get("ncdBS").getClass();
                    if (isArr.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr = bodyjson.getJSONArray("ncdBS");
                        for (int i = 0; i < batcharr.size(); i++) {
                            JSONObject dataJson = batcharr.getJSONObject(i);
                            String factorCode = GetJV(dataJson, "factorCode");
                            String ciadjustreason = GetJV(dataJson, "ciadjustreason");
                            String NOADJUSTREASON = GetJV(dataJson, "noAdjustReason");
                            String coefficient = GetJV(dataJson, "coefficient");
                            String adjustValue = GetJV(dataJson, "adjustValue");
                            String insertsql = ''' 
                                 Insert into PRE_QUOTATION_NCDBS
                                 (
                                 sysid,
                                 ORDERNO,
                                 FACTORCODE,
                                 CIADJUSTREASON,
                                 NOADJUSTREASON,
                                 COEFFICIENT,
                                 CREATEDDATE,
                                 adjustValue
                                 )values(
                                 sysguid,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 sysdate,
                                 ?                              
                                 )
                                 '''
                            jt.update(insertsql, ORDERNO, factorCode, ciadjustreason, NOADJUSTREASON, coefficient, adjustValue);


                        }
                    } else if (isArr.getName().equals("net.sf.json.JSONObject")) {
                        String ncdBSbody = GetJV(bodyjson, "ncdBS")
                        JSONObject batcharr = JSONObject.fromObject(ncdBSbody);
                        String factorCode = GetJV(batcharr, "factorCode");
                        String ciadjustreason = GetJV(batcharr, "ciadjustreason");
                        String NOADJUSTREASON = GetJV(batcharr, "noAdjustReason");
                        String coefficient = GetJV(batcharr, "coefficient");
                        String adjustValue = GetJV(batcharr, "adjustValue");
                        String insertsql = ''' 
                                 Insert into PRE_QUOTATION_NCDBS
                                 (
                                 sysid,
                                 ORDERNO,
                                 FACTORCODE,
                                 CIADJUSTREASON,
                                 NOADJUSTREASON,
                                 COEFFICIENT,
                                 CREATEDDATE,
                                 adjustValue
                                 )values(
                                 sysguid,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 sysdate,
                                 ?                             
                                 )

                                 '''

                        jt.update(insertsql, ORDERNO, factorCode, ciadjustreason, NOADJUSTREASON, coefficient, adjustValue);


                    }


                    //商业险险别信息
                    //插入表前,先把旧数据删掉
                    String delsql2 = '''DELETE FROM  PRE_QUOTATION_RISKITEMINFO WHERE ORDERNO=? ''';
                    jt.update(delsql2, ORDERNO);

                    Class<?> itemKindBSarr = jsonObject.getJSONObject("response").getJSONObject("body").get("itemKindBS").getClass();
                    if (itemKindBSarr.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("itemKindBS");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String kindCode = batcharr2.get(b).get("kindCode");//险别代码
                            String kindName = batcharr2.get(b).get("kindName");//险别名称
                            String relatedInd = batcharr2.get(b).get("relatedInd");//是否投保不计免赔
                            String quantity = batcharr2.get(b).get("quantity");//数量
                            String discount = batcharr2.get(b).get("discount");//折扣率
                            String priceTaxTotal = batcharr2.get(b).get("priceTaxTotal");//价税合计
                            String sumInsured = batcharr2.get(b).get("sumInsured");//保额
                            String deductibleRate = batcharr2.get(b).get("deductibleRate");//约定损失比例
                            String serviceTimes = batcharr2.get(b).get("serviceTimes");//服务次数
                            String benchmarkPremium = batcharr2.get(b).get("benchmarkPremium");//基准保费
                            String insertsql = ''' 
                                 Insert into PRE_QUOTATION_RISKITEMINFO
                                 (
                                 sysid,
                                 ORDERNO,
                                 SY_KINDCODE,
                                 SY_KINDNAME,
                                 SY_SUMINSURED,
                                 SY_PRICETAXTOTAL,
                                 SY_DEDUCTIBLERATE,
                                 SY_SERVICETIMES,
                                 SY_QUANTITY,
                                 relatedInd,
                                 quantity,
                                 discount,
                                 CREATEDDATE,
                                 benchmarkPremium
                                 )values(
                                 sysguid,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 sysdate,
                                 ?                                 
                                 )
                                 '''

                            jt.update(insertsql, ORDERNO, kindCode, kindName, sumInsured, priceTaxTotal, deductibleRate, serviceTimes, quantity, relatedInd, quantity, discount,benchmarkPremium);

                        }
                    } else if (itemKindBSarr.getName().equals("net.sf.json.JSONObject")) {
                        String itemKindBSbody = GetJV(bodyjson, "itemKindBS")
                        JSONObject batcharr = JSONObject.fromObject(itemKindBSbody);
                        String kindCode = GetJV(batcharr, "kindCode");//险别代码
                        String kindName = GetJV(batcharr, "kindName");//险别名称
                        String relatedInd = GetJV(batcharr, "relatedInd");//是否投保不计免赔
                        String quantity = GetJV(batcharr, "quantity");//数量
                        String discount = GetJV(batcharr, "discount");//折扣率
                        String priceTaxTotal = GetJV(batcharr, "priceTaxTotal");//价税合计
                        String sumInsured = GetJV(batcharr, "sumInsured");//保额
                        String deductibleRate = GetJV(batcharr, "deductibleRate");//约定损失比例
                        String serviceTimes = GetJV(batcharr, "serviceTimes");//服务次数
                        String benchmarkPremium = GetJV(batcharr, "benchmarkPremium");//基准保费
                        String insertsql = ''' 
                                 Insert into PRE_QUOTATION_RISKITEMINFO
                                 (
                                 sysid,
                                 ORDERNO,
                                 SY_KINDCODE,
                                 SY_KINDNAME,
                                 SY_SUMINSURED,
                                 SY_PRICETAXTOTAL,
                                 SY_DEDUCTIBLERATE,
                                 SY_SERVICETIMES,
                                 SY_QUANTITY,
                                 relatedInd,
                                 quantity,
                                 discount,
                                 CREATEDDATE,
                                 benchmarkPremium
                                 )values(
                                 sysguid,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 ?,
                                 sysdate,
                                 ?                                 
                                 )
                                 '''

                        jt.update(insertsql, ORDERNO, kindCode, kindName, sumInsured, priceTaxTotal, deductibleRate, serviceTimes, quantity, relatedInd, quantity, discount,benchmarkPremium);

                    }

                    //插入表前,先把车辆表旧数据删掉
                    String cardelsql = '''DELETE FROM  PRE_QUOTATION_VEHICLEINFO WHERE ORDERNO=? ''';
                    jt.update(cardelsql, ORDERNO);

                    String carinsersql = '''
    INSERT INTO PRE_QUOTATION_VEHICLEINFO
  (ORDERNO,
   BRANDNAME,
   LICENSENO,
   FRAMENO,
   ENGINENO,
   SINGEINDATE,
   CARCHECKSTATUS,
   CHGOWNERFLAG,
   TRANSFERDATE,
   BSCHGOWNERFLAG,
   SEATCOUNT,
   LOANVEHICLEFLAG,
   NEGOTIATEDACTUALVALUE,
   ACTUALVALUE,
   CARKINDCODE,
   PURCHASEPRICE,
   ATTACHNATURE,
   USENATURESHOW,
   CARUSETYPE,
   CERTIFICATEDATE,
   ENROLLDATE,
   COMPLETEKERBMASS,
   VEHICLECATEGORY,
   ENERGYTYPE,
   SUITCLAUSE,
   CREATEDDATE,
   DISTINGUISHVANAREACODE,
   COMMERCIALCARGRADE,
   ZJXLGRADE,
   LICENSECOLORCODE,
   CIMODELCODE,
   CIMODELNAME,
   DRIVEUSEATTRIBUTE
   
   )
VALUES
  (?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   sysdate,?,?,?,?,?,?,?)


                              ''';
                    jt.update(carinsersql,
                            ORDERNO,
                            brandName,
                            licenseNo,
                            frameNo,
                            engineNo,
                            singeinDate,
                            carCheckStatus,
                            chgOwnerFlag,
                            transferDate,
                            bschgOwnerFlag,
                            seatCount,
                            loanVehicleFlag,
                            negotiatedActualValue,
                            actualValue,
                            carKindCode,
                            purchasePrice,
                            attachNature,
                            useNatureShow,
                            carUseType,
                            certificateDate,
                            enrollDate,
                            completeKerbMass,
                            vehicleCategory,
                            energyType,
                            suitClause,distinguishVanAreaCode,commercialCarGrade,zjxlGrade,licenseColorCode,ciModelCode,ciModelName,driveUseAttribute
                    )

                    /**
                     //评分信息
                     String delsql3 = ''' DELETE FROM PRE_QUOTATION_ACTUARY WHERE ORDERNO=?''';
                     jt.update(delsql3, ORDERNO);
                     Class<?> isArr2 = jsonObject.getJSONObject("response").getJSONObject("body").get("actuary").getClass();

                     if (isArr2.getName().equals("net.sf.json.JSONArray")) {
                     JSONArray batcharr2 = bodyjson.getJSONArray("actuary");
                     for (int b = 0; b < batcharr2.size(); b++) {
                     String actuaryName = batcharr2.get(b).get("actuaryName");//评分名称
                     String actuaryCode = batcharr2.get(b).get("actuaryCode");//评分Code
                     String actuaryValue = batcharr2.get(b).get("actuaryValue");//评分值


                     String insersql = '''
                     Insert into PRE_QUOTATION_ACTUARY
                     (sysid,
                     ORDERNO,
                     CUSTOMER_GUID,
                     ACTUARYNAME,
                     ACTUARYCODE,
                     ACTUARYVALUE,
                     CREATEDDATE
                     )values(
                     sysguid,
                     ?,
                     ?,
                     ?,
                     ?,
                     ?,
                     sysdate
                     )
                     ''';

                     jt.update(insersql, ORDERNO, customer_guid, actuaryName, actuaryCode, actuaryValue);

                     }


                     } else if (isArr2.getName().equals("net.sf.json.JSONObject")) {
                     String actuarybody = GetJV(bodyjson, "actuary")
                     JSONObject batcharr = JSONObject.fromObject(actuarybody);
                     String actuaryName = GetJV(batcharr, "actuaryName");//评分名称
                     String actuaryCode = GetJV(batcharr, "actuaryCode");//评分Code
                     String actuaryValue = GetJV(batcharr, "actuaryValue");//评分值

                     String insersql = '''
                     Insert into PRE_QUOTATION_ACTUARY
                     (sysid,
                     ORDERNO,
                     CUSTOMER_GUID,
                     ACTUARYNAME,
                     ACTUARYCODE,
                     ACTUARYVALUE,
                     CREATEDDATE
                     )values(
                     sysguid,
                     ?,
                     ?,
                     ?,
                     ?,
                     ?,
                     sysdate
                     )
                     ''';

                     jt.update(insersql, ORDERNO, customer_guid, actuaryName, actuaryCode, actuaryValue);

                     }
                     **/
                    //预审核保信息
                    String delsql4 = ''' DELETE FROM PRE_QUOTATION_FLOWUW WHERE ORDERNO=?''';
                    jt.update(delsql4, ORDERNO);
                    Class<?> isArr3 = jsonObject.getJSONObject("response").getJSONObject("body").get("flowUW").getClass();


                    if (isArr3.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("flowUW");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String resultType = batcharr2.get(b).get("resultType");//结果类型
                            String ruleId = batcharr2.get(b).get("ruleId");//规则编号
                            String description = batcharr2.get(b).get("description");//描述


                            String insersql = '''
                                    Insert into PRE_QUOTATION_FLOWUW
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    resultType,
                                    ruleId,
                                    description,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    sysdate
                                    )
                                         ''';

                            jt.update(insersql, ORDERNO, customer_guid, resultType, ruleId, description);


                        }
                    } else if (isArr3.getName().equals("net.sf.json.JSONObject")) {
                        String flowUWbody = GetJV(bodyjson, "flowUW")
                        JSONObject batcharr = JSONObject.fromObject(flowUWbody);
                        String resultType = GetJV(batcharr, "resultType");//结果类型
                        String ruleId = GetJV(batcharr, "ruleId");//规则编号
                        String description = GetJV(batcharr, "description");//描述

                        String insersql = '''
                                    Insert into PRE_QUOTATION_FLOWUW
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    resultType,
                                    ruleId,
                                    description,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    sysdate
                                    )
                                         ''';

                        jt.update(insersql, ORDERNO, customer_guid, resultType, ruleId, description);


                    }


                    //预审复核信息

                    String delsql5 = ''' DELETE FROM PRE_QUOTATION_flowApprov WHERE ORDERNO=?''';
                    jt.update(delsql5, ORDERNO);
                    Class<?> isArr4 = jsonObject.getJSONObject("response").getJSONObject("body").get("flowApprov").getClass();


                    if (isArr4.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("flowApprov");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String resultType = batcharr2.get(b).get("resultType");//结果类型
                            String ruleId = batcharr2.get(b).get("ruleId");//规则编号
                            String description = batcharr2.get(b).get("description");//描述


                            String insersql = '''
                                    Insert into PRE_QUOTATION_flowApprov
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    resultType,
                                    ruleId,
                                    description,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    sysdate
                                    )
                                         ''';

                            jt.update(insersql, ORDERNO, customer_guid, resultType, ruleId, description);


                        }
                    } else if (isArr4.getName().equals("net.sf.json.JSONObject")) {
                        String flowUWbody = GetJV(bodyjson, "flowUW")
                        JSONObject batcharr = JSONObject.fromObject(flowUWbody);
                        String resultType = GetJV(batcharr, "resultType");//结果类型
                        String ruleId = GetJV(batcharr, "ruleId");//规则编号
                        String description = GetJV(batcharr, "description");//描述

                        String insersql = '''
                                    Insert into PRE_QUOTATION_flowApprov
                                    (sysid,
                                    ORDERNO,
                                    CUSTOMER_GUID,
                                    resultType,
                                    ruleId,
                                    description,
                                    CREATEDDATE
                                    )values(
                                    sysguid,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    ?,
                                    sysdate
                                    )
                                         ''';

                        jt.update(insersql, ORDERNO, customer_guid, resultType, ruleId, description);


                    }

                    //违法信息
                    String delsql6 = ''' DELETE FROM PRE_QUOTATION_PECCANCYLIST WHERE ORDERNO=?''';
                    jt.update(delsql6, ORDERNO);
                    Class<?> isArr5 = jsonObject.getJSONObject("response").getJSONObject("body").get("peccancyList").getClass();


                    if (isArr5.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("peccancyList");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String peccancyAction = batcharr2.get(b).get("peccancyAction");//违法行为代码
                            String peccancyType = batcharr2.get(b).get("peccancyType");//违法记录类型
                            String peccancyCount = batcharr2.get(b).get("peccancyCount");//违法行为次数
                            String drinkDrivingCount = batcharr2.get(b).get("drinkDrivingCount");//醉酒驾驶次数
                            String peccancyTime = batcharr2.get(b).get("peccancyTime");//违法时间
                            String accEptDate = batcharr2.get(b).get("accEptDate");//违法受理时间
                            String peccancyAddress = batcharr2.get(b).get("peccancyAddress");//违法地点
                            String coeff = batcharr2.get(b).get("coeff");//调整系数
                            String insersql = '''
                                       Insert into PRE_QUOTATION_PECCANCYLIST
                                       (
                                       sysid,
                                       ORDERNO,
                                       PECCANCYACTION,
                                       PECCANCYTYPE,
                                       PECCANCYCOUNT,
                                       DRINKDRIVINGCOUNT,
                                       PECCANCYTIME,
                                       ACCEPTDATE,
                                       PECCANCYADDRESS,
                                       COEFF,
                                       CREATEDDATE,
                                       CUSTOMER_GUID
                                       )
                                       values
                                       (
                                       sysguid,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       sysdate,
                                       ?
                                       )
                                        ''';

                            jt.update(insersql, ORDERNO, peccancyAction, peccancyType, peccancyCount, drinkDrivingCount, peccancyTime, accEptDate, peccancyAddress, coeff);

                        }

                    } else if (isArr5.getName().equals("net.sf.json.JSONObject")) {
                        String peccancyListbody = GetJV(bodyjson, "peccancyList")
                        JSONObject batcharr = JSONObject.fromObject(peccancyListbody);

                        String peccancyAction = GetJV(batcharr, "peccancyAction");//违法行为代码
                        String peccancyType = GetJV(batcharr, "peccancyType");//违法记录类型
                        String peccancyCount = GetJV(batcharr, "peccancyCount");//违法行为次数
                        String drinkDrivingCount = GetJV(batcharr, "drinkDrivingCount");//醉酒驾驶次数
                        String peccancyTime = GetJV(batcharr, "peccancyTime");//违法时间
                        String accEptDate = GetJV(batcharr, "accEptDate");//违法受理时间
                        String peccancyAddress = GetJV(batcharr, "peccancyAddress");//违法地点
                        String coeff = GetJV(batcharr, "coeff");//调整系数

                        String insersql = '''
                                       Insert into PRE_QUOTATION_PECCANCYLIST
                                       (
                                       sysid,
                                       ORDERNO,
                                       PECCANCYACTION,
                                       PECCANCYTYPE,
                                       PECCANCYCOUNT,
                                       DRINKDRIVINGCOUNT,
                                       PECCANCYTIME,
                                       ACCEPTDATE,
                                       PECCANCYADDRESS,
                                       COEFF,
                                       CREATEDDATE,
                                       CUSTOMER_GUID
                                       )
                                       values
                                       (
                                       sysguid,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       sysdate,
                                       ?
                                       )
                                        ''';

                        jt.update(insersql, ORDERNO, peccancyAction, peccancyType, peccancyCount, drinkDrivingCount, peccancyTime, accEptDate, peccancyAddress, coeff);


                    }

                    //费率因子节点
                    String delsql7 = ''' DELETE FROM PRE_QUOTATION_riskProfit WHERE ORDERNO=?''';
                    jt.update(delsql7, ORDERNO);
                    Class<?> isArr6 = jsonObject.getJSONObject("response").getJSONObject("body").get("riskProfit").getClass();

                    if (isArr6.getName().equals("net.sf.json.JSONArray")) {
                        JSONArray batcharr2 = bodyjson.getJSONArray("riskProfit");
                        for (int b = 0; b < batcharr2.size(); b++) {
                            String profitCode = batcharr2.get(b).get("profitCode");//费率因子代码
                            String profitName = batcharr2.get(b).get("profitName");//违法记录类型
                            String rate = batcharr2.get(b).get("rate");//费率系数值

                            String insertsql = ''' 
                                       Insert into 
                                       PRE_QUOTATION_riskProfit (
                                         sysid,
                                       ORDERNO,
                                       PROFITCODE,
                                       profitName,
                                       rate,
                                       customer_guid,
                                       CREATEDDATE
                                       )values(
                                       sysguid,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       sysdate
                                       )
                                              '''
                            jt.update(insertsql, ORDERNO, profitCode, profitName, rate, customer_guid);


                        }
                    } else if (isArr6.getName().equals("net.sf.json.JSONObject")) {
                        String peccancyListbody = GetJV(bodyjson, "riskProfit")
                        JSONObject batcharr = JSONObject.fromObject(peccancyListbody);

                        String profitCode = GetJV(batcharr, "profitCode");//费率因子代码
                        String profitName = GetJV(batcharr, "profitName");//违法记录类型
                        String rate = GetJV(batcharr, "rate");//费率系数值

                        String insertsql = ''' 
                                       Insert into 
                                       PRE_QUOTATION_riskProfit (
                                         sysid,
                                       ORDERNO,
                                       PROFITCODE,
                                       profitName,
                                       rate,
                                       customer_guid,
                                       CREATEDDATE
                                       )values(
                                       sysguid,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       ?,
                                       sysdate
                                       )
                                              '''
                        jt.update(insertsql, ORDERNO, profitCode, profitName, rate, customer_guid);


                    }


                    //评分主信息
                    //查询评分表里是否存在
                    String delsqlzb = ''' 
                               DELETE   from  pre_quotation_maininfo WHERE ORDERNO=?
                                  ''';

                    jt.update(delsqlzb,ORDERNO);

                    //插入预评分主表
                    String insertsql = ''' 
                          INSERT INTO pre_quotation_maininfo
          (ORDERNO,
           REGISTERNO,
           LOSSTIME,
           ENDCASETIME,
           CLAIMNOTIFICATIONNO,
           ACCIDENTDEATHFLAG,
           LOSSFEE,
           CLAIMTIMES,
           INSUREYEARS,
           CLAIMADJUSTLEVEL,
           DAMAGEDTIMES,
           CUSTOMERNAME,
           IDENTIFYNUMBER,
           BIRTHDATE,
           SEX,
           OWNERNATURE,
           IDENTIFYTYPE,
           LINKEDFLAG,
           DISCOUNTUP,
           DISCOUNTDOWN,
           TPFLAG,
           XZXID,
           PREMIUMTRIALFLAG,
           COMPANYCODE,
           COMPANYNAME,
           policyNo,
           demandNo,
           CREATEDDATE,customer_guid)
        VALUES
          (
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,
           ?,       
           sysdate,?)    
                      ''';




                    jt.update(insertsql,
                            ORDERNO,
                            registerNo,
                            lossTime,
                            endCaseTime,
                            claimNotificationNo,
                            accidentDeathFlag,
                            lossFee,
                            claimTimes,
                            insureYears,
                            claimAdJustLevel,
                            damagedTimes,
                            name,
                            identifyNumber,
                            birthDate,
                            sex,
                            ownerNature,
                            identifyType,
                            linkedFlag,
                            discountUp,
                            discountDown,
                            tpFlag,
                            xzxId,
                            premiumTrialFlag,
                            companyCode,
                            companyName,
                            policyNo,
                            demandNo,
                            customer_guid
                    );

                    //把推送表数据改成成功
                    String updatesql = ''' 
                   Update push_h5_customer 
                    set
                   flag='1',
                   MODIFIEDDATE=sysdate,
                   MODIFIEDGROUP='SYSTEM',
                   MODIFIEDBY='SELITE',
                   REQUESTINFO=?,
                   REQUESTDATE=sysdate,
                   RESPONSEINFO=?,
                   RESPONSEDATE=sysdate
                   where CUSTOMER_GUID=?
                      ''';
                    jt.update(updatesql, defrequstInfo.toString(), postCallBackBody.toString(), customer_guid);

                    //插入轨迹表
                    String PUSH_H5_CUSTOMER_HISTORYinsertsql = '''
                    insert into PUSH_H5_CUSTOMER_HISTORY
                    (
                    sysid,
                    CUSTOMER_GUID,
                    CUSLISTNAME,
                    CREATEDGROUP,
                    CREATEDBY,
                    CREATEDDATE,
                    ISFLAG,
                    REQUESTINFO,
                    REQUESTDATE,
                    RESPONSEINFO,
                    RESPONSEDATE,
                    ROLEGROUP_ID,
                    REAMRK
                    )
                    select 
                    sysguid,
                    CUSTOMER_GUID,
                    CUSLISTNAME,
                    CREATEDGROUP,
                    CREATEDBY,
                    sysdate,
                    ISFLAG,
                    REQUESTINFO,
                    REQUESTDATE,
                    RESPONSEINFO,
                    RESPONSEDATE,
                    ROLEGROUP_ID,
                    '成功推送'
                    from PUSH_H5_CUSTOMER pu5
                    where  pu5.customer_guid=?
                    ''';

                    jt.update(PUSH_H5_CUSTOMER_HISTORYinsertsql, customer_guid);


                }else{
                    log.debug("【预评分】推送H5 xbPremiumCalculate返回报文标识失败,该推送名单标识为失败！");
                    updatestate(eliteBean, customer_guid, defrequstInfo.toString(), postCallBackBody.toString(),errMsg);
                }




            } else {

                //城市信息找不到失败
                updatestate(eliteBean, customer_guid, "城市信息找不到", "城市信息找不到","城市信息找不到");
            }
        } catch (Exception e) {
            log.error("【预评分】V03接口推送H5异常：" + e.getMessage());

            updatestateXL(eliteBean, customer_guid, defrequstInfo.toString(), e.getMessage(),e.getMessage());
        }

        return "";

    }


    /**
     * 修改push_h5_customer状态
     * @param eliteBean
     * @param customer_guid
     * @param state
     */
    public static String updatestate(EliteBean eliteBean, String customer_guid, String requstinfo, String repesoninfo,String errmsg ) {
        JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());


        String updatesql = ''' 
                   Update push_h5_customer 
                    set
                   flag='2',
                   MODIFIEDDATE=sysdate,
                   MODIFIEDGROUP='SYSTEM',
                   MODIFIEDBY='SELITE',
                   REQUESTINFO=?,
                   REQUESTDATE=sysdate,
                   RESPONSEINFO=?,
                   RESPONSEDATE=sysdate,
                   errmsg=?,
                   loserattemptnum=loserattemptnum+1
                   where CUSTOMER_GUID=?
                      ''';
        jt.update(updatesql, requstinfo, repesoninfo, errmsg,customer_guid);

        String  insertsql='''
        insert into PUSH_H5_CUSTOMER_HISTORY
        (
        sysid,
        CUSTOMER_GUID,
        CUSLISTNAME,
        CREATEDGROUP,
        CREATEDBY,
        CREATEDDATE,
        ISFLAG,
        REQUESTINFO,
        REQUESTDATE,
        RESPONSEINFO,
        RESPONSEDATE,
        ROLEGROUP_ID,
        REAMRK,
        errmsg,
        loserattemptnum
        )
                select
        sysguid,
        CUSTOMER_GUID,
        CUSLISTNAME,
        CREATEDGROUP,
        CREATEDBY,
        sysdate,
        ISFLAG,
        REQUESTINFO,
        REQUESTDATE,
        RESPONSEINFO,
        RESPONSEDATE,
        ROLEGROUP_ID,
        '推送失败',
        errmsg,
        loserattemptnum
        from PUSH_H5_CUSTOMER pu5
        where  pu5.customer_guid=?
                '''
        jt.update(insertsql, customer_guid);







        return "";
    }


    /**
     * 修改push_h5_customer状态
     * @param eliteBean
     * @param customer_guid
     * @param state
     */
    public static String updatestateXL(EliteBean eliteBean, String customer_guid, String requstinfo, String repesoninfo,String errmsg ) {
        JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());


        String updatesql = ''' 
                   Update push_h5_customer 
                    set
                   flag='2',
                   MODIFIEDDATE=sysdate,
                   MODIFIEDGROUP='SYSTEM',
                   MODIFIEDBY='SELITE',
                   REQUESTINFO=?,
                   REQUESTDATE=sysdate,
                   RESPONSEINFO=?,
                   RESPONSEDATE=sysdate,
                   errmsg=?,
                   loserattemptnum=loserattemptnum+1
                   where CUSTOMER_GUID=?
                      ''';
        jt.update(updatesql, requstinfo, repesoninfo, errmsg,customer_guid);

        String  insertsql='''
        insert into PUSH_H5_CUSTOMER_HISTORY
        (
        sysid,
        CUSTOMER_GUID,
        CUSLISTNAME,
        CREATEDGROUP,
        CREATEDBY,
        CREATEDDATE,
        ISFLAG,
        REQUESTINFO,
        REQUESTDATE,
        RESPONSEINFO,
        RESPONSEDATE,
        ROLEGROUP_ID,
        REAMRK,
        errmsg,
        loserattemptnum
        )
                select
        sysguid,
        CUSTOMER_GUID,
        CUSLISTNAME,
        CREATEDGROUP,
        CREATEDBY,
        sysdate,
        ISFLAG,
        REQUESTINFO,
        REQUESTDATE,
        RESPONSEINFO,
        RESPONSEDATE,
        ROLEGROUP_ID,
        '推送失败',
        errmsg,
        loserattemptnum
        from PUSH_H5_CUSTOMER pu5
        where  pu5.customer_guid=?
                '''
        jt.update(insertsql, customer_guid);





        //判断尝试次数是否到达参数配置次数,到达就不自动推送了
        List cishuList=eliteBean.chaxun_sql("select loserattemptnum From push_h5_customer where CUSTOMER_GUID='"+customer_guid+"' ","dataSource");

        int  loserattemptnum=cishuList.get(0).get("loserattemptnum");

        int pznum= KHDBConfig.getParam(eliteBean, "PFCSS", "") as int;

        if (loserattemptnum.toInteger()<pznum.toInteger()){
            log.debug("【预评分】正常尝试重推："+customer_guid+"[已经尝试次数：]"+loserattemptnum);
            String updatesql2 = ''' 
                   Update push_h5_customer 
                    set
                   flag='0',
                   MODIFIEDDATE=sysdate,
                   MODIFIEDGROUP='SYSTEM',
                   MODIFIEDBY='SELITE',
                   REQUESTINFO='',
                   RESPONSEINFO='',
                   errmsg=''
                   where CUSTOMER_GUID=?
                      ''';
            jt.update(updatesql2,customer_guid);

            String insertsql2='''insert into Elitethread
(THREAD_GUID,CREATEDATE,Status,Content,Type)values(
sysguid,sysdate,0,?,'YPF')
''';

            jt.update(insertsql2,customer_guid);



        }else {

            log.debug("【预评分】已经到达配置的尝试次数："+customer_guid+"[已经尝试次数：]"+loserattemptnum);
        }



        return "";
    }
    public static byte[] sign(final byte[] text, final byte[] privateKeyData,
                              final String algorithm) throws GeneralSecurityException {
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyData);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");

        PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
        Signature signatureChecker = Signature.getInstance(algorithm);
        signatureChecker.initSign(privateKey);
        signatureChecker.update(text);
        return signatureChecker.sign();
    }


    public static boolean verify(final byte[] text, final byte[] signedText,
                                 final byte[] publicKeyData, final String algorithm)
            throws GeneralSecurityException {
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyData);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey publicKey = keyFactory.generatePublic(keySpec);
        Signature signatureChecker = Signature.getInstance(algorithm);
        signatureChecker.initVerify(publicKey);
        signatureChecker.update(text);
        return signatureChecker.verify(signedText);
    }



    public static class DefaultTrustManager implements X509TrustManager {

        @Override
        public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}

        @Override
        public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    }


    public static String getStreamAsString(InputStream stream, String charset) throws IOException {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset));
            StringWriter writer = new StringWriter();

            char[] chars = new char[256];
            int count = 0;
            while ((count = reader.read(chars)) > 0) {
                writer.write(chars, 0, count);
            }

            return writer.toString();
        } finally {
            if (stream != null) {
                stream.close();
            }
        }
    }


    public static String GetJV(JSONObject inJson, String getKey) {
        String Rev_Value = null;
        try {
            Rev_Value = inJson.getString(getKey);
            //log.debug("GetJV 获取参数值(String)-" + getKey + ":" + Rev_Value);
        } catch (Exception e) {
            try {
                Rev_Value = String.valueOf(inJson.getInt(getKey));
                //log.debug("GetJV 获取参数值(Integer)-" + getKey + ":" + Rev_Value);
            } catch (Exception e1) {
                Rev_Value = "";
                //log.debug("GetJV 获取参数值Exception-" + getKey + ":" + Rev_Value);
            }
        } finally {
            if (Rev_Value == null || Rev_Value.equals("null") || Rev_Value.length() <= 0) {
                //log.debug("GetJV 获取参数值Exception-" + getKey + ":" + Rev_Value);
                Rev_Value = "";
            }
        }
        return Rev_Value;
    }
}
